diff options
author | 2015-06-29 20:16:15 +0000 | |
---|---|---|
committer | 2015-06-29 20:16:15 +0000 | |
commit | 64106c4d3d4ddba8c7bc2af75376e6d3d3d75601 (patch) | |
tree | 8c64d6e8be006486d975a651505fbbde61365cd6 /carboxyl/struct.SignalMut.html | |
download | irsc-gh-pages.tar.gz irsc-gh-pages.tar.xz irsc-gh-pages.zip |
Update documentationgh-pages
Diffstat (limited to 'carboxyl/struct.SignalMut.html')
-rw-r--r-- | carboxyl/struct.SignalMut.html | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/carboxyl/struct.SignalMut.html b/carboxyl/struct.SignalMut.html new file mode 100644 index 0000000..884baec --- /dev/null +++ b/carboxyl/struct.SignalMut.html @@ -0,0 +1,164 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <meta name="generator" content="rustdoc"> + <meta name="description" content="API documentation for the Rust `SignalMut` struct in crate `carboxyl`."> + <meta name="keywords" content="rust, rustlang, rust-lang, SignalMut"> + + <title>carboxyl::SignalMut - Rust</title> + + <link rel="stylesheet" type="text/css" href="../main.css"> + + + +</head> +<body class="rustdoc"> + <!--[if lte IE 8]> + <div class="warning"> + This old browser is unsupported and will most likely display funky + things. + </div> + <![endif]--> + + + + <section class="sidebar"> + + <p class='location'><a href='index.html'>carboxyl</a></p><script>window.sidebarCurrent = {name: 'SignalMut', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script> + </section> + + <nav class="sub"> + <form class="search-form js-only"> + <div class="search-container"> + <input class="search-input" name="search" + autocomplete="off" + placeholder="Click or press 'S' to search, '?' for more options..." + type="search"> + </div> + </form> + </nav> + + <section id='main' class="content struct"> +<h1 class='fqn'><span class='in-band'>Struct <a href='index.html'>carboxyl</a>::<wbr><a class='struct' href=''>SignalMut</a></span><span class='out-of-band'><span id='render-detail'> + <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs"> + [<span class='inner'>−</span>] + </a> + </span><a id='src-3299' class='srclink' href='../src/carboxyl/signal.rs.html#435-437' title='goto source code'>[src]</a></span></h1> +<pre class='rust struct'>pub struct SignalMut<A> { + // some fields omitted +}</pre><div class='docblock'><p>Signal variant using inner mutability for efficient in-place updates.</p> + +<p>This is the only kind of primitive that allows non-<code>Clone</code> types to be +wrapped into functional reactive abstractions. The API is somewhat different +from that of a regular signal to accommodate this.</p> + +<p>One cannot directly sample a <code>SignalMut</code> as this would require a clone. +Instead it comes with a couple of adaptor methods that mimick a subset of +the <code>Signal</code> API. However, all functions passed to these methods take the +argument coming from the <code>SignalMut</code> by reference.</p> +</div><h2 id='methods'>Methods</h2><h3 class='impl'><code>impl<A: <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Send.html' title='core::marker::Send'>Send</a> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Sync.html' title='core::marker::Sync'>Sync</a> + 'static> <a class='struct' href='../carboxyl/struct.SignalMut.html' title='carboxyl::SignalMut'>SignalMut</a><A></code></h3><div class='impl-items'><h4 id='method.snapshot' class='method'><code>fn <a href='#method.snapshot' class='fnname'>snapshot</a><B, C, F>(&self, stream: &<a class='struct' href='../carboxyl/struct.Stream.html' title='carboxyl::Stream'>Stream</a><B>, f: F) -> <a class='struct' href='../carboxyl/struct.Stream.html' title='carboxyl::Stream'>Stream</a><C> <span class='where'>where B: <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Send.html' title='core::marker::Send'>Send</a> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Sync.html' title='core::marker::Sync'>Sync</a> + 'static, C: <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Send.html' title='core::marker::Send'>Send</a> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Sync.html' title='core::marker::Sync'>Sync</a> + 'static, F: <a class='trait' href='http://doc.rust-lang.org/nightly/core/ops/trait.Fn.html' title='core::ops::Fn'>Fn</a>(&A, B) -> C + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Send.html' title='core::marker::Send'>Send</a> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Sync.html' title='core::marker::Sync'>Sync</a> + 'static</span></code></h4> +<div class='docblock'><p>Semantically the same as <code>Signal::snapshot</code></p> + +<p>The key difference here is, that the combining function takes its first +argument by reference, as it can't be moved out of the <code>SignalMut</code>.</p> + +<h1 id="example" class='section-header'><a + href="#example">Example</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>sink1</span> <span class='op'>=</span> <span class='ident'>Sink</span>::<span class='ident'>new</span>(); +<span class='kw'>let</span> <span class='ident'>sink2</span> <span class='op'>=</span> <span class='ident'>Sink</span>::<span class='ident'>new</span>(); +<span class='comment'>// Collect values in a mutable `Vec`</span> +<span class='kw'>let</span> <span class='ident'>values</span> <span class='op'>=</span> <span class='ident'>sink1</span>.<span class='ident'>stream</span>().<span class='ident'>scan_mut</span>(<span class='macro'>vec</span><span class='macro'>!</span>[], <span class='op'>|</span><span class='ident'>v</span>, <span class='ident'>a</span><span class='op'>|</span> <span class='ident'>v</span>.<span class='ident'>push</span>(<span class='ident'>a</span>)); +<span class='comment'>// Snapshot some value from it</span> +<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>index</span> <span class='op'>=</span> <span class='ident'>values</span>.<span class='ident'>snapshot</span>(<span class='kw-2'>&</span><span class='ident'>sink2</span>.<span class='ident'>stream</span>(), + <span class='op'>|</span><span class='ident'>v</span>, <span class='ident'>k</span><span class='op'>|</span> <span class='ident'>v</span>.<span class='ident'>get</span>(<span class='ident'>k</span>).<span class='ident'>map</span>(<span class='op'>|</span><span class='ident'>x</span><span class='op'>|</span> <span class='op'>*</span><span class='ident'>x</span>) +).<span class='ident'>events</span>(); + +<span class='ident'>sink1</span>.<span class='ident'>send</span>(<span class='number'>4</span>); +<span class='ident'>sink1</span>.<span class='ident'>send</span>(<span class='number'>5</span>); +<span class='ident'>sink2</span>.<span class='ident'>send</span>(<span class='number'>0</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>index</span>.<span class='ident'>next</span>(), <span class='prelude-val'>Some</span>(<span class='prelude-val'>Some</span>(<span class='number'>4</span>))); + +<span class='ident'>sink2</span>.<span class='ident'>send</span>(<span class='number'>1</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>index</span>.<span class='ident'>next</span>(), <span class='prelude-val'>Some</span>(<span class='prelude-val'>Some</span>(<span class='number'>5</span>))); + +<span class='ident'>sink2</span>.<span class='ident'>send</span>(<span class='number'>2</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>index</span>.<span class='ident'>next</span>(), <span class='prelude-val'>Some</span>(<span class='prelude-val'>None</span>)); +</pre> +</div><h4 id='method.combine' class='method'><code>fn <a href='#method.combine' class='fnname'>combine</a><B, C, F>(&self, signal: &<a class='struct' href='../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><B>, f: F) -> <a class='struct' href='../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><C> <span class='where'>where B: <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Send.html' title='core::marker::Send'>Send</a> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Sync.html' title='core::marker::Sync'>Sync</a> + 'static, C: <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Send.html' title='core::marker::Send'>Send</a> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Sync.html' title='core::marker::Sync'>Sync</a> + 'static, F: <a class='trait' href='http://doc.rust-lang.org/nightly/core/ops/trait.Fn.html' title='core::ops::Fn'>Fn</a>(&A, B) -> C + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Send.html' title='core::marker::Send'>Send</a> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Sync.html' title='core::marker::Sync'>Sync</a> + 'static</span></code></h4> +<div class='docblock'><p>Similar to <code>lift2</code>. Combines a <code>SignalMut</code> with a <code>Signal</code> using a +function. The function takes its first argument by reference.</p> +</div><h4 id='method.combine_mut' class='method'><code>fn <a href='#method.combine_mut' class='fnname'>combine_mut</a><B, C, F>(&self, other: &<a class='struct' href='../carboxyl/struct.SignalMut.html' title='carboxyl::SignalMut'>SignalMut</a><B>, f: F) -> <a class='struct' href='../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><C> <span class='where'>where B: <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Send.html' title='core::marker::Send'>Send</a> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Sync.html' title='core::marker::Sync'>Sync</a> + 'static, C: <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Send.html' title='core::marker::Send'>Send</a> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Sync.html' title='core::marker::Sync'>Sync</a> + 'static, F: <a class='trait' href='http://doc.rust-lang.org/nightly/core/ops/trait.Fn.html' title='core::ops::Fn'>Fn</a>(&A, &B) -> C + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Send.html' title='core::marker::Send'>Send</a> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Sync.html' title='core::marker::Sync'>Sync</a> + 'static</span></code></h4> +<div class='docblock'><p>Similar to <code>lift2</code>, but combines two <code>SignalMut</code> using a function. The +supplied function takes both arguments by reference.</p> + +<h1 id="example" class='section-header'><a + href="#example">Example</a></h1><pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>sink</span>: <span class='ident'>Sink</span><span class='op'><</span><span class='ident'>i32</span><span class='op'>></span> <span class='op'>=</span> <span class='ident'>Sink</span>::<span class='ident'>new</span>(); +<span class='kw'>let</span> <span class='ident'>sum</span> <span class='op'>=</span> <span class='ident'>sink</span>.<span class='ident'>stream</span>().<span class='ident'>scan_mut</span>(<span class='number'>0</span>, <span class='op'>|</span><span class='ident'>sum</span>, <span class='ident'>a</span><span class='op'>|</span> <span class='op'>*</span><span class='ident'>sum</span> <span class='op'>+=</span> <span class='ident'>a</span>); +<span class='kw'>let</span> <span class='ident'>product</span> <span class='op'>=</span> <span class='ident'>sink</span>.<span class='ident'>stream</span>().<span class='ident'>scan_mut</span>(<span class='number'>1</span>, <span class='op'>|</span><span class='ident'>prod</span>, <span class='ident'>a</span><span class='op'>|</span> <span class='op'>*</span><span class='ident'>prod</span> <span class='op'>*=</span> <span class='ident'>a</span>); +<span class='kw'>let</span> <span class='ident'>combo</span> <span class='op'>=</span> <span class='ident'>sum</span>.<span class='ident'>combine_mut</span>(<span class='kw-2'>&</span><span class='ident'>product</span>, <span class='op'>|</span><span class='ident'>s</span>, <span class='ident'>p</span><span class='op'>|</span> (<span class='op'>*</span><span class='ident'>s</span>, <span class='op'>*</span><span class='ident'>p</span>)); + +<span class='ident'>sink</span>.<span class='ident'>send</span>(<span class='number'>1</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>combo</span>.<span class='ident'>sample</span>(), (<span class='number'>1</span>, <span class='number'>1</span>)); + +<span class='ident'>sink</span>.<span class='ident'>send</span>(<span class='number'>3</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>combo</span>.<span class='ident'>sample</span>(), (<span class='number'>4</span>, <span class='number'>3</span>)); + +<span class='ident'>sink</span>.<span class='ident'>send</span>(<span class='number'>5</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>combo</span>.<span class='ident'>sample</span>(), (<span class='number'>9</span>, <span class='number'>15</span>)); +</pre> +</div></div></section> + <section id='search' class="content hidden"></section> + + <section class="footer"></section> + + <div id="help" class="hidden"> + <div class="shortcuts"> + <h1>Keyboard shortcuts</h1> + <dl> + <dt>?</dt> + <dd>Show this help dialog</dd> + <dt>S</dt> + <dd>Focus the search field</dd> + <dt>⇤</dt> + <dd>Move up in search results</dd> + <dt>⇥</dt> + <dd>Move down in search results</dd> + <dt>⏎</dt> + <dd>Go to active search result</dd> + </dl> + </div> + <div class="infos"> + <h1>Search tricks</h1> + <p> + Prefix searches with a type followed by a colon (e.g. + <code>fn:</code>) to restrict the search to a given type. + </p> + <p> + Accepted types are: <code>fn</code>, <code>mod</code>, + <code>struct</code>, <code>enum</code>, + <code>trait</code>, <code>typedef</code> (or + <code>tdef</code>). + </p> + <p> + Search functions by type signature (e.g. + <code>vec -> usize</code>) + </p> + </div> + </div> + + + + <script> + window.rootPath = "../"; + window.currentCrate = "carboxyl"; + window.playgroundUrl = ""; + </script> + <script src="../jquery.js"></script> + <script src="../main.js"></script> + + <script async src="../search-index.js"></script> +</body> +</html>
\ No newline at end of file |