Skip to content

Commit

Permalink
(automated) deploy from commit 1bd6b79
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tiny-kirin committed Jun 16, 2024
1 parent 9cc88fb commit ff3122b
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 68 deletions.
52 changes: 30 additions & 22 deletions src/wiwi/with_cloned/mod.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@
<a href="#184" id="184">184</a>
<a href="#185" id="185">185</a>
<a href="#186" id="186">186</a>
<a href="#187" id="187">187</a>
<a href="#188" id="188">188</a>
<a href="#189" id="189">189</a>
<a href="#190" id="190">190</a>
</pre></div><pre class="rust"><code><span class="doccomment">/// Executes code with cloned values, so the executed code
/// can take ownership of the value without moving the original
///
Expand Down Expand Up @@ -240,10 +244,10 @@
</span><span class="doccomment">/// assert_eq!(*shared_data.lock().unwrap(), 420);
/// ```
///
/// ... this is not great, since you'd have to use `_shared_data` to refer to
/// the cloned value.
/// ... this is not great, since you'd have to use `_shared_data` with an
/// underscore to refer to the cloned value.
///
/// But alternatively, it can be done with a temporary scope:
/// It can also be done with a temporary scope:
///
/// ```
/// # use std::sync::{ Arc, Mutex };
Expand All @@ -262,14 +266,16 @@
/// assert_eq!(*shared_data.lock().unwrap(), 420);
/// ```
///
/// ... not really what we would do, but still not optimal either way.
/// ... not really what we would do (really only minor style preferences, nothing
/// actually relating to function), but still not optimal either way.
///
/// In our short(...ish?) time writing rust code, I've already noticed I use
/// this pattern a lot when dealing with shared state across threads. There are
/// likely patterns that we don't know about (...or do, but haven't thought about
/// at time of writing this documentation :p), and also maybe not always specifically
/// `Arc&lt;Mutex&lt;Data&gt;&gt;`. Needing to write all that boilerplate for a very simple
/// and straightforward operation, doesn't feel very ergonomic or elegant.
/// In our short(...ish?) time writing rust code, I've already noticed I use this
/// pattern a lot when dealing with shared state across threads. There are likely
/// patterns that we don't know about, that would do something similar here (clone
/// a value, then consume the clone, then access original). Or maybe we do know
/// about them, but we haven't thought about it at time of writing this documentation
/// :p. Needing to write all that boilerplate code for an otherwise very simple
/// operation, doesn't feel very ergonomic or elegant, and quickly gets boring.
///
/// This macro can help with that:
///
Expand All @@ -293,15 +299,15 @@
/// assert_eq!(*shared_data.lock().unwrap(), 420);
/// ```
///
/// In my opinion, a bit less boilerplate, and a bit nicer.
/// It cut out most of the boilerplate, and just feels a lot nicer to use.
///
/// The syntax of the macro is, first a list of the variables that should have a
/// cloned version available, followed by keyword `in`, then any statements
/// you would like to run. Essentially, you can think of the stuff after `in`
/// as just a regular block. Those who know what [swift closures look like] may
/// recognise this syntax :p
/// The syntax of the macro is, first a (comma seperated) list of the variables
/// that should have a cloned version available, followed by keyword `in`, then
/// any statements you would like to run. Essentially, you can think of the stuff
/// after `in` as just a regular block. Those who know what [swift closures] look
/// like may recognise this syntax hehe
///
/// [swift closures look like]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/closures#Closure-Expression-Syntax
/// [swift closures]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/closures#Closure-Expression-Syntax
///
/// You can also bind the cloned values mutably, as well as return values out
/// of the macro:
Expand All @@ -311,6 +317,8 @@
/// let string = String::new();
///
/// let modified_string = with_cloned! { mut string in
/// // ^^^
///
/// // do whatever
/// string.push_str("uwu");
///
Expand All @@ -326,17 +334,17 @@
/// ```
///
/// Ideally you could bind variables mutably or not on a per variable basis,
/// but I can't seem to find a way to do so, unfortunately &gt;&lt; so it's all or
/// nothing for now.
/// but unfortunately, I can't seem to find a way to do so elegantly &gt;~&lt; so it's
/// all or nothing for now.
///
/// Random, but the below code snippets are equivalent:
///
/// ```
/// # use wiwi::with_cloned::with_cloned;
/// # let value = String::new();
/// let cloned1 = value.clone();
/// // clones it for the inner code, but the inner code just returns it
/// // ... so it's just a clone
/// // macro clones it for the inner code, but the inner code
/// // just returns it... so it is just a clone
/// let cloned2 = with_cloned! { value in value };
///
/// assert_eq!(value, cloned1);
Expand All @@ -345,7 +353,7 @@
</span><span class="attr">#[macro_export]
</span><span class="macro">macro_rules!</span> with_cloned {
($(<span class="macro-nonterminal">$stuff</span>:tt)<span class="kw-2">*</span>) =&gt; {
<span class="comment">// hide potential distracting implementation detail in docs
<span class="comment">// hide potential distracting implementation details in docs
</span><span class="macro-nonterminal">$</span><span class="macro">crate::with_cloned::_with_cloned_impl!</span> { $(<span class="macro-nonterminal">$stuff</span>)* }
}
}
Expand Down
2 changes: 1 addition & 1 deletion wiwi/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ <h3 id="enabled-features-wiwikiwingay"><a class="doc-anchor" href="#enabled-feat
<li><code>with-cloned (unstable)</code></li>
<li><code>z85</code></li>
</ul>
<p>These docs have been built from commit <a href="https://github.com/meadowsys/wiwi/commit/ba80bae6e4d491826251811fe9b65287cad2de53">ba80bae6</a>.</p>
<p>These docs have been built from commit <a href="https://github.com/meadowsys/wiwi/commit/1bd6b79f8bf34065718057d4d98a06fc0c8dc9e7">1bd6b79f</a>.</p>
<div class="footnotes"><hr><ol><li id="fn1"><p>Based on the benchmark available in this repo: wiwi is about 21.5x faster in encode, and 7.5x faster in decode. I want better benchmarks though. For now the <code>hex</code> crate also provides more flexibility, whereas <code>wiwi::hex</code> just exposes <code>encode_hex</code>, <code>encode_upper_hex</code>, and <code>decode_hex</code> functions.
&nbsp;<a href="#fnref1"></a></p></li><li id="fn2"><p>Based on the benchmark available in this repo: wiwi is about 1.4x faster in encode, and 2.2x faster in decode. I want better benchmarks though. There is no functionality that the <code>z85</code> crate provides, that we don’t also provide (<code>encode_z85</code> and <code>decode_z85</code> functions).&nbsp;<a href="#fnref2"></a></p></li></ol></div></div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="aoc/index.html" title="mod wiwi::aoc">aoc</a><span class="stab portability" title="Available on crate feature `aoc-unstable` only"><code>aoc-unstable</code></span></div></li><li><div class="item-name"><a class="mod" href="auth/index.html" title="mod wiwi::auth">auth</a><span class="stab portability" title="Available on crate feature `auth-unstable` only"><code>auth-unstable</code></span></div></li><li><div class="item-name"><a class="mod" href="bitstream/index.html" title="mod wiwi::bitstream">bitstream</a><span class="stab portability" title="Available on crate feature `bitstream-unstable` only"><code>bitstream-unstable</code></span></div></li><li><div class="item-name"><a class="mod" href="chainer/index.html" title="mod wiwi::chainer">chainer</a><span class="stab portability" title="Available on crate feature `chainer-unstable` only"><code>chainer-unstable</code></span></div></li><li><div class="item-name"><a class="mod" href="clock_timer/index.html" title="mod wiwi::clock_timer">clock_timer</a><span class="stab portability" title="Available on crate feature `clock-timer` only"><code>clock-timer</code></span></div><div class="desc docblock-short">An interval tracking clock</div></li><li><div class="item-name"><a class="mod" href="debounce/index.html" title="mod wiwi::debounce">debounce</a><span class="stab portability" title="Available on crate feature `debounce` only"><code>debounce</code></span></div><div class="desc docblock-short">A debounced function; or a function that won’t actually get called until
there haven’t been calls to it for a certain amount of time.</div></li><li><div class="item-name"><a class="mod" href="defer/index.html" title="mod wiwi::defer">defer</a><span class="stab portability" title="Available on crate feature `defer-unstable` only"><code>defer-unstable</code></span></div></li><li><div class="item-name"><a class="mod" href="h/index.html" title="mod wiwi::h">h</a><span class="stab portability" title="Available on crate feature `h` only"><code>h</code></span></div><div class="desc docblock-short">h</div></li><li><div class="item-name"><a class="mod" href="hex/index.html" title="mod wiwi::hex">hex</a><span class="stab portability" title="Available on crate feature `hex` only"><code>hex</code></span></div><div class="desc docblock-short">Fast and efficient implementation of hex encoding.</div></li><li><div class="item-name"><a class="mod" href="id/index.html" title="mod wiwi::id">id</a><span class="stab portability" title="Available on crate feature `id-unstable` only"><code>id-unstable</code></span></div></li><li><div class="item-name"><a class="mod" href="int/index.html" title="mod wiwi::int">int</a><span class="stab portability" title="Available on crate feature `int-unstable` only"><code>int-unstable</code></span></div></li><li><div class="item-name"><a class="mod" href="iter/index.html" title="mod wiwi::iter">iter</a><span class="stab portability" title="Available on crate feature `iter-unstable` only"><code>iter-unstable</code></span></div></li><li><div class="item-name"><a class="mod" href="lazy_wrap/index.html" title="mod wiwi::lazy_wrap">lazy_wrap</a><span class="stab portability" title="Available on crate feature `lazy-wrap` only"><code>lazy-wrap</code></span></div><div class="desc docblock-short">Wrapper for initialisation function, initialising it only on first access.</div></li><li><div class="item-name"><a class="mod" href="lsl/index.html" title="mod wiwi::lsl">lsl</a><span class="stab portability" title="Available on crate feature `lsl-unstable` only"><code>lsl-unstable</code></span></div></li><li><div class="item-name"><a class="mod" href="memory_usage/index.html" title="mod wiwi::memory_usage">memory_usage</a><span class="stab portability" title="Available on crate feature `memory-usage-unstable` only"><code>memory-usage-unstable</code></span></div></li><li><div class="item-name"><a class="mod" href="minesweeper/index.html" title="mod wiwi::minesweeper">minesweeper</a><span class="stab portability" title="Available on crate feature `minesweeper-unstable` only"><code>minesweeper-unstable</code></span></div></li><li><div class="item-name"><a class="mod" href="nominal/index.html" title="mod wiwi::nominal">nominal</a><span class="stab portability" title="Available on crate feature `nominal` only"><code>nominal</code></span></div><div class="desc docblock-short">Generic, zero-cost struct that wraps data in a newtype, to take advantage of
Expand Down
Loading

0 comments on commit ff3122b

Please sign in to comment.