diff options
Diffstat (limited to 'carboxyl')
31 files changed, 2007 insertions, 0 deletions
diff --git a/carboxyl/index.html b/carboxyl/index.html new file mode 100644 index 0000000..345e4c3 --- /dev/null +++ b/carboxyl/index.html @@ -0,0 +1,272 @@ +<!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 `carboxyl` crate."> + <meta name="keywords" content="rust, rustlang, rust-lang, carboxyl"> + + <title>carboxyl - 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'></p><script>window.sidebarCurrent = {name: 'carboxyl', ty: 'mod', relpath: '../'};</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 mod"> +<h1 class='fqn'><span class='in-band'>Crate <a class='mod' href=''>carboxyl</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-0' class='srclink' href='../src/carboxyl/lib.rs.html#1-161' title='goto source code'>[src]</a></span></h1> +<div class='docblock'><p><em>Carboxyl</em> provides primitives for functional reactive programming in Rust. +It draws inspiration from the <a href="https://github.com/SodiumFRP/sodium/">Sodium</a> libraries and Push-Pull FRP, +as described by <a href="http://conal.net/papers/push-pull-frp/push-pull-frp.pdf">Elliott (2009)</a>.</p> + +<h1 id="overview" class='section-header'><a + href="#overview">Overview</a></h1> +<p>Functional reactive programming (FRP) is a composable and modular +abstraction for creating dynamic and reactive systems. In its most general +form it models these systems as a composition of two basic primitives: +<em>streams</em> are a series of singular events and <em>signals</em> are continuously +changing values.</p> + +<p><em>Carboxyl</em> is an imperative, hybrid push- and pull-based implementation of +FRP. Streams and the discrete components of signals are data-driven, i.e. +whenever an event occurs the resulting changes are propagated to everything +that depends on it.</p> + +<p>However, the continuous components of signals are demand-driven. Internally, +<em>Carboxyl</em> stores the state of a signal as a function. This function has to +be evaluated by consumers of a signal to obtain a concrete value.</p> + +<p>Nonetheless, <em>Carboxyl</em> has no explicit notion of time. Its signals are +functions that can be evaluated at any time, but they do not carry any +inherent notion of time. Synchronization and atomicity is achieved by a +transaction system.</p> + +<h1 id="functional-reactive-primitives" class='section-header'><a + href="#functional-reactive-primitives">Functional reactive primitives</a></h1> +<p>This library provides two basic types: <code>Stream</code> and <code>Signal</code>. A stream is a +discrete sequence of events, a signal is a container for values that change +(discretely) over time.</p> + +<p>The FRP primitives are mostly implemented as methods of the basic types to +ease method chaining, except for the various lifting functions, as they do +not really belong to any type in particular.</p> + +<p>In addition, the <code>Sink</code> type allows one to create a stream of events by +sending values into it. It is the only way to create a stream from scratch, +i.e. without using any of the other primitives.</p> + +<h1 id="usage-example" class='section-header'><a + href="#usage-example">Usage example</a></h1> +<p>Here is a simple example of how you can use the primitives provided by +<em>Carboxyl</em>. First of all, events can be sent into a <em>sink</em>. From a sink one +can create a <em>stream</em> of events. Streams can also be filtered, mapped and +merged. One can e.g. hold the last event from a stream as a signal.</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>use</span> <span class='ident'>carboxyl</span>::<span class='ident'>Sink</span>; + +<span class='kw'>let</span> <span class='ident'>sink</span> <span class='op'>=</span> <span class='ident'>Sink</span>::<span class='ident'>new</span>(); +<span class='kw'>let</span> <span class='ident'>stream</span> <span class='op'>=</span> <span class='ident'>sink</span>.<span class='ident'>stream</span>(); +<span class='kw'>let</span> <span class='ident'>signal</span> <span class='op'>=</span> <span class='ident'>stream</span>.<span class='ident'>hold</span>(<span class='number'>3</span>); + +<span class='comment'>// The current value of the signal is initially 3</span> +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>signal</span>.<span class='ident'>sample</span>(), <span class='number'>3</span>); + +<span class='comment'>// When we fire an event, the signal get updated accordingly</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'>signal</span>.<span class='ident'>sample</span>(), <span class='number'>5</span>); +</pre> + +<p>One can also directly iterate over the stream instead of holding it in a +signal:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>events</span> <span class='op'>=</span> <span class='ident'>stream</span>.<span class='ident'>events</span>(); +<span class='ident'>sink</span>.<span class='ident'>send</span>(<span class='number'>4</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>events</span>.<span class='ident'>next</span>(), <span class='prelude-val'>Some</span>(<span class='number'>4</span>)); +</pre> + +<p>Streams and signals can be combined using various primitives. We can map a +stream to another stream using a function:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>squares</span> <span class='op'>=</span> <span class='ident'>stream</span>.<span class='ident'>map</span>(<span class='op'>|</span><span class='ident'>x</span><span class='op'>|</span> <span class='ident'>x</span> <span class='op'>*</span> <span class='ident'>x</span>).<span class='ident'>hold</span>(<span class='number'>0</span>); +<span class='ident'>sink</span>.<span class='ident'>send</span>(<span class='number'>4</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>squares</span>.<span class='ident'>sample</span>(), <span class='number'>16</span>); +</pre> + +<p>Or we can filter a stream to create a new one that only contains events that +satisfy a certain predicate:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>negatives</span> <span class='op'>=</span> <span class='ident'>stream</span>.<span class='ident'>filter</span>(<span class='op'>|</span><span class='kw-2'>&</span><span class='ident'>x</span><span class='op'>|</span> <span class='ident'>x</span> <span class='op'><</span> <span class='number'>0</span>).<span class='ident'>hold</span>(<span class='number'>0</span>); + +<span class='comment'>// This won't arrive at the signal.</span> +<span class='ident'>sink</span>.<span class='ident'>send</span>(<span class='number'>4</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>negatives</span>.<span class='ident'>sample</span>(), <span class='number'>0</span>); + +<span class='comment'>// But this will!</span> +<span class='ident'>sink</span>.<span class='ident'>send</span>(<span class='op'>-</span><span class='number'>3</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>negatives</span>.<span class='ident'>sample</span>(), <span class='op'>-</span><span class='number'>3</span>); +</pre> + +<p>There are some other methods on streams and signals, that you can find in +their respective APIs.</p> + +<p>Note that all these objects are <code>Send + Sync + Clone</code>. This means you can +easily pass them around in your code, make clones, give them to another +thread, and they will still be updated correctly.</p> + +<p>You may have noticed that certain primitives take a function as an argument. +There is a limitation on what kind of functions can and should be used here. +In general, as FRP provides an abstraction around mutable state, they should +be pure functions (i.e. free of side effects).</p> + +<p>For the most part this is guaranteed by Rust's type system. A static +function with a matching signature always works. A closure though is very +restricted: it must not borrow its environment, as it is impossible to +satisfy the lifetime requirements for that. So you can only move stuff into +it from the environment. However, the moved contents of the closure may also +not be altered, which is guaranteed by the <code>Fn(…) -> …)</code> trait bound.</p> + +<p>However, both closures and functions could still have side effects such as +I/O, changing mutable state via <code>Mutex</code> or <code>RefCell</code>, etc. While Rust's type +system cannot prevent this, you should generally not pass such functions to +the FRP primitives, as they break the benefits you get from using FRP. +(An exception here is debugging output.)</p> +</div><h2 id='modules' class='section-header'><a href="#modules">Modules</a></h2> +<table> + <tr class=' module-item'> + <td><a class='mod' href='lift/index.html' + title='carboxyl::lift'>lift</a></td> + <td class='docblock short'> + <p>Lifting of n-ary functions.</p> + + </td> + </tr> + </table><h2 id='macros' class='section-header'><a href="#macros">Macros</a></h2> +<table> + <tr class=' module-item'> + <td><a class='macro' href='macro.lift!.html' + title='carboxyl::lift!'>lift!</a></td> + <td class='docblock short'> + + </td> + </tr> + </table><h2 id='structs' class='section-header'><a href="#structs">Structs</a></h2> +<table> + <tr class=' module-item'> + <td><a class='struct' href='struct.Signal.html' + title='carboxyl::Signal'>Signal</a></td> + <td class='docblock short'> + <p>A continuous signal that changes over time.</p> + + </td> + </tr> + + <tr class=' module-item'> + <td><a class='struct' href='struct.SignalMut.html' + title='carboxyl::SignalMut'>SignalMut</a></td> + <td class='docblock short'> + <p>Signal variant using inner mutability for efficient in-place updates.</p> + + </td> + </tr> + + <tr class=' module-item'> + <td><a class='struct' href='struct.Sink.html' + title='carboxyl::Sink'>Sink</a></td> + <td class='docblock short'> + <p>An event sink.</p> + + </td> + </tr> + + <tr class=' module-item'> + <td><a class='struct' href='struct.Stream.html' + title='carboxyl::Stream'>Stream</a></td> + <td class='docblock short'> + <p>A stream of events.</p> + + </td> + </tr> + </table></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 diff --git a/carboxyl/lift/fn.lift0.html b/carboxyl/lift/fn.lift0.html new file mode 100644 index 0000000..f7fd88e --- /dev/null +++ b/carboxyl/lift/fn.lift0.html @@ -0,0 +1,102 @@ +<!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 `lift0` fn in crate `carboxyl`."> + <meta name="keywords" content="rust, rustlang, rust-lang, lift0"> + + <title>carboxyl::lift::lift0 - 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>::<wbr><a href='index.html'>lift</a></p><script>window.sidebarCurrent = {name: 'lift0', ty: 'fn', 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 fn"> +<h1 class='fqn'><span class='in-band'>Function <a href='../index.html'>carboxyl</a>::<wbr><a href='index.html'>lift</a>::<wbr><a class='fn' href=''>lift0</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-3653' class='srclink' href='../../src/carboxyl/lift.rs.html#58-62' title='goto source code'>[src]</a></span></h1> +<pre class='rust fn'>pub fn lift0<A, F>(f: F) -> <a class='struct' href='../../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><A> <span class='where'>where F: <a class='trait' href='http://doc.rust-lang.org/nightly/core/ops/trait.Fn.html' title='core::ops::Fn'>Fn</a>() -> 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</span></pre><div class='docblock'><p>Lift a 0-ary function.</p> +</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 diff --git a/carboxyl/lift/fn.lift1.html b/carboxyl/lift/fn.lift1.html new file mode 100644 index 0000000..5f7204d --- /dev/null +++ b/carboxyl/lift/fn.lift1.html @@ -0,0 +1,102 @@ +<!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 `lift1` fn in crate `carboxyl`."> + <meta name="keywords" content="rust, rustlang, rust-lang, lift1"> + + <title>carboxyl::lift::lift1 - 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>::<wbr><a href='index.html'>lift</a></p><script>window.sidebarCurrent = {name: 'lift1', ty: 'fn', 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 fn"> +<h1 class='fqn'><span class='in-band'>Function <a href='../index.html'>carboxyl</a>::<wbr><a href='index.html'>lift</a>::<wbr><a class='fn' href=''>lift1</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-3679' class='srclink' href='../../src/carboxyl/lift.rs.html#66-92' title='goto source code'>[src]</a></span></h1> +<pre class='rust fn'>pub fn lift1<A, B, F>(f: F, sa: &<a class='struct' href='../../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><A>) -> <a class='struct' href='../../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><B> <span class='where'>where 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> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + 'static, B: <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> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</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 + <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></pre><div class='docblock'><p>Lift a unary function.</p> +</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 diff --git a/carboxyl/lift/fn.lift2.html b/carboxyl/lift/fn.lift2.html new file mode 100644 index 0000000..8fbae6d --- /dev/null +++ b/carboxyl/lift/fn.lift2.html @@ -0,0 +1,102 @@ +<!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 `lift2` fn in crate `carboxyl`."> + <meta name="keywords" content="rust, rustlang, rust-lang, lift2"> + + <title>carboxyl::lift::lift2 - 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>::<wbr><a href='index.html'>lift</a></p><script>window.sidebarCurrent = {name: 'lift2', ty: 'fn', 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 fn"> +<h1 class='fqn'><span class='in-band'>Function <a href='../index.html'>carboxyl</a>::<wbr><a href='index.html'>lift</a>::<wbr><a class='fn' href=''>lift2</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-3840' class='srclink' href='../../src/carboxyl/lift.rs.html#96-147' title='goto source code'>[src]</a></span></h1> +<pre class='rust fn'>pub fn lift2<A, B, C, F>(f: F, sa: &<a class='struct' href='../../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><A>, sb: &<a class='struct' href='../../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><B>) -> <a class='struct' href='../../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><C> <span class='where'>where 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> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + 'static, B: <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> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + 'static, 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> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</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></pre><div class='docblock'><p>Lift a binary function.</p> +</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 diff --git a/carboxyl/lift/fn.lift3.html b/carboxyl/lift/fn.lift3.html new file mode 100644 index 0000000..2501d07 --- /dev/null +++ b/carboxyl/lift/fn.lift3.html @@ -0,0 +1,102 @@ +<!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 `lift3` fn in crate `carboxyl`."> + <meta name="keywords" content="rust, rustlang, rust-lang, lift3"> + + <title>carboxyl::lift::lift3 - 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>::<wbr><a href='index.html'>lift</a></p><script>window.sidebarCurrent = {name: 'lift3', ty: 'fn', 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 fn"> +<h1 class='fqn'><span class='in-band'>Function <a href='../index.html'>carboxyl</a>::<wbr><a href='index.html'>lift</a>::<wbr><a class='fn' href=''>lift3</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-4162' class='srclink' href='../../src/carboxyl/lift.rs.html#150-159' title='goto source code'>[src]</a></span></h1> +<pre class='rust fn'>pub fn lift3<F, A, B, C, Ret>(f: F, ca: &<a class='struct' href='../../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><A>, cb: &<a class='struct' href='../../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><B>, cc: &<a class='struct' href='../../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><C>) -> <a class='struct' href='../../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><Ret> <span class='where'>where 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) -> Ret + <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: <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> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + 'static, B: <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> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + 'static, 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> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + 'static, Ret: <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> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + 'static</span></pre><div class='docblock'><p>Lift a ternary function.</p> +</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 diff --git a/carboxyl/lift/fn.lift4.html b/carboxyl/lift/fn.lift4.html new file mode 100644 index 0000000..ca930a1 --- /dev/null +++ b/carboxyl/lift/fn.lift4.html @@ -0,0 +1,102 @@ +<!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 `lift4` fn in crate `carboxyl`."> + <meta name="keywords" content="rust, rustlang, rust-lang, lift4"> + + <title>carboxyl::lift::lift4 - 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>::<wbr><a href='index.html'>lift</a></p><script>window.sidebarCurrent = {name: 'lift4', ty: 'fn', 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 fn"> +<h1 class='fqn'><span class='in-band'>Function <a href='../index.html'>carboxyl</a>::<wbr><a href='index.html'>lift</a>::<wbr><a class='fn' href=''>lift4</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-4253' class='srclink' href='../../src/carboxyl/lift.rs.html#162-176' title='goto source code'>[src]</a></span></h1> +<pre class='rust fn'>pub fn lift4<F, A, B, C, D, Ret>(f: F, ca: &<a class='struct' href='../../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><A>, cb: &<a class='struct' href='../../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><B>, cc: &<a class='struct' href='../../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><C>, cd: &<a class='struct' href='../../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><D>) -> <a class='struct' href='../../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><Ret> <span class='where'>where 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, D) -> Ret + <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: <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> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + 'static, B: <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> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + 'static, 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> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + 'static, D: <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> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + 'static, Ret: <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> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + 'static</span></pre><div class='docblock'><p>Lift a quarternary function.</p> +</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 diff --git a/carboxyl/lift/index.html b/carboxyl/lift/index.html new file mode 100644 index 0000000..57f4038 --- /dev/null +++ b/carboxyl/lift/index.html @@ -0,0 +1,173 @@ +<!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 `lift` mod in crate `carboxyl`."> + <meta name="keywords" content="rust, rustlang, rust-lang, lift"> + + <title>carboxyl::lift - 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: 'lift', ty: 'mod', 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 mod"> +<h1 class='fqn'><span class='in-band'>Module <a href='../index.html'>carboxyl</a>::<wbr><a class='mod' href=''>lift</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-3641' class='srclink' href='../../src/carboxyl/lift.rs.html#1-254' title='goto source code'>[src]</a></span></h1> +<div class='docblock'><p>Lifting of n-ary functions.</p> + +<p>A lift maps a function on values to a function on signals. Given a function of +type <code>F: Fn(A, B, …) -> R</code> and signals of types <code>Signal<A>, Signal<B>, …</code> the +<code>lift!</code> macro creates a <code>Signal<R></code>, whose content is computed using the +function.</p> + +<p>Currently lift is only implemented for functions with up to four arguments. +This limitation is due to the current implementation strategy (and maybe +limitations of Rust's type system), but it can be increased to arbitrary but +finite arity if required.</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_a</span> <span class='op'>=</span> <span class='ident'>Sink</span>::<span class='ident'>new</span>(); +<span class='kw'>let</span> <span class='ident'>sink_b</span> <span class='op'>=</span> <span class='ident'>Sink</span>::<span class='ident'>new</span>(); +<span class='kw'>let</span> <span class='ident'>product</span> <span class='op'>=</span> <span class='macro'>lift</span><span class='macro'>!</span>( + <span class='op'>|</span><span class='ident'>a</span>, <span class='ident'>b</span><span class='op'>|</span> <span class='ident'>a</span> <span class='op'>*</span> <span class='ident'>b</span>, + <span class='kw-2'>&</span><span class='ident'>sink_a</span>.<span class='ident'>stream</span>().<span class='ident'>hold</span>(<span class='number'>0</span>), + <span class='kw-2'>&</span><span class='ident'>sink_b</span>.<span class='ident'>stream</span>().<span class='ident'>hold</span>(<span class='number'>0</span>) +); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>product</span>.<span class='ident'>sample</span>(), <span class='number'>0</span>); +<span class='ident'>sink_a</span>.<span class='ident'>send</span>(<span class='number'>3</span>); +<span class='ident'>sink_b</span>.<span class='ident'>send</span>(<span class='number'>5</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>product</span>.<span class='ident'>sample</span>(), <span class='number'>15</span>); +</pre> +</div><h2 id='functions' class='section-header'><a href="#functions">Functions</a></h2> +<table> + <tr class=' module-item'> + <td><a class='fn' href='fn.lift0.html' + title='carboxyl::lift::lift0'>lift0</a></td> + <td class='docblock short'> + <p>Lift a 0-ary function.</p> + + </td> + </tr> + + <tr class=' module-item'> + <td><a class='fn' href='fn.lift1.html' + title='carboxyl::lift::lift1'>lift1</a></td> + <td class='docblock short'> + <p>Lift a unary function.</p> + + </td> + </tr> + + <tr class=' module-item'> + <td><a class='fn' href='fn.lift2.html' + title='carboxyl::lift::lift2'>lift2</a></td> + <td class='docblock short'> + <p>Lift a binary function.</p> + + </td> + </tr> + + <tr class=' module-item'> + <td><a class='fn' href='fn.lift3.html' + title='carboxyl::lift::lift3'>lift3</a></td> + <td class='docblock short'> + <p>Lift a ternary function.</p> + + </td> + </tr> + + <tr class=' module-item'> + <td><a class='fn' href='fn.lift4.html' + title='carboxyl::lift::lift4'>lift4</a></td> + <td class='docblock short'> + <p>Lift a quarternary function.</p> + + </td> + </tr> + </table></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 diff --git a/carboxyl/lift/sidebar-items.js b/carboxyl/lift/sidebar-items.js new file mode 100644 index 0000000..2b8d168 --- /dev/null +++ b/carboxyl/lift/sidebar-items.js @@ -0,0 +1 @@ +initSidebarItems({"fn":[["lift0","Lift a 0-ary function."],["lift1","Lift a unary function."],["lift2","Lift a binary function."],["lift3","Lift a ternary function."],["lift4","Lift a quarternary function."]]});
\ No newline at end of file diff --git a/carboxyl/macro.lift!.html b/carboxyl/macro.lift!.html new file mode 100644 index 0000000..a0d54e3 --- /dev/null +++ b/carboxyl/macro.lift!.html @@ -0,0 +1,119 @@ +<!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 `lift!` macro in crate `carboxyl`."> + <meta name="keywords" content="rust, rustlang, rust-lang, lift!"> + + <title>carboxyl::lift! - 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: 'lift!', ty: 'macro', 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 macro"> +<h1 class='fqn'><span class='in-band'><a href='index.html'>carboxyl</a>::<wbr><a class='macro' href=''>lift!</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-4374' class='srclink' href='../src/carboxyl/lift.rs.html#39-54' title='goto source code'>[src]</a></span></h1> +<pre class='rust macro'> +<span class='macro'>macro_rules</span><span class='macro'>!</span> <span class='ident'>lift</span> { + (<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>f</span>: <span class='ident'>expr</span>) + <span class='op'>=></span> ( <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>crate</span>::<span class='ident'>lift</span>::<span class='ident'>lift0</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>f</span>) ); + + (<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>f</span>: <span class='ident'>expr</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>a</span>: <span class='ident'>expr</span>) + <span class='op'>=></span> ( <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>crate</span>::<span class='ident'>lift</span>::<span class='ident'>lift1</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>f</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>a</span>) ); + + (<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>f</span>: <span class='ident'>expr</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>a</span>: <span class='ident'>expr</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>b</span>: <span class='ident'>expr</span>) + <span class='op'>=></span> ( <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>crate</span>::<span class='ident'>lift</span>::<span class='ident'>lift2</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>f</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>a</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>b</span>) ); + + (<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>f</span>: <span class='ident'>expr</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>a</span>: <span class='ident'>expr</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>b</span>: <span class='ident'>expr</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>c</span>: <span class='ident'>expr</span>) + <span class='op'>=></span> ( <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>crate</span>::<span class='ident'>lift</span>::<span class='ident'>lift3</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>f</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>a</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>b</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>c</span>) ); + + (<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>f</span>: <span class='ident'>expr</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>a</span>: <span class='ident'>expr</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>b</span>: <span class='ident'>expr</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>c</span>: <span class='ident'>expr</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>d</span>: <span class='ident'>expr</span>) + <span class='op'>=></span> ( <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>crate</span>::<span class='ident'>lift</span>::<span class='ident'>lift4</span>(<span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>f</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>a</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>b</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>c</span>, <span class='macro-nonterminal'>$</span><span class='macro-nonterminal'>d</span>) ); +} +</pre> +</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 diff --git a/carboxyl/pending/index.html b/carboxyl/pending/index.html new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/carboxyl/pending/index.html diff --git a/carboxyl/pending/sidebar-items.js b/carboxyl/pending/sidebar-items.js new file mode 100644 index 0000000..48333d3 --- /dev/null +++ b/carboxyl/pending/sidebar-items.js @@ -0,0 +1 @@ +initSidebarItems({});
\ No newline at end of file diff --git a/carboxyl/readonly/index.html b/carboxyl/readonly/index.html new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/carboxyl/readonly/index.html diff --git a/carboxyl/readonly/sidebar-items.js b/carboxyl/readonly/sidebar-items.js new file mode 100644 index 0000000..48333d3 --- /dev/null +++ b/carboxyl/readonly/sidebar-items.js @@ -0,0 +1 @@ +initSidebarItems({});
\ No newline at end of file diff --git a/carboxyl/sidebar-items.js b/carboxyl/sidebar-items.js new file mode 100644 index 0000000..55a962e --- /dev/null +++ b/carboxyl/sidebar-items.js @@ -0,0 +1 @@ +initSidebarItems({"macro":[["lift!",""]],"mod":[["lift","Lifting of n-ary functions."]],"struct":[["Signal","A continuous signal that changes over time."],["SignalMut","Signal variant using inner mutability for efficient in-place updates."],["Sink","An event sink."],["Stream","A stream of events."]]});
\ No newline at end of file diff --git a/carboxyl/signal/index.html b/carboxyl/signal/index.html new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/carboxyl/signal/index.html diff --git a/carboxyl/signal/sidebar-items.js b/carboxyl/signal/sidebar-items.js new file mode 100644 index 0000000..452ea30 --- /dev/null +++ b/carboxyl/signal/sidebar-items.js @@ -0,0 +1 @@ +initSidebarItems({"struct":[["Signal","A continuous signal that changes over time."],["SignalMut","Signal variant using inner mutability for efficient in-place updates."]]});
\ No newline at end of file diff --git a/carboxyl/signal/struct.Signal.html b/carboxyl/signal/struct.Signal.html new file mode 100644 index 0000000..34bb4ea --- /dev/null +++ b/carboxyl/signal/struct.Signal.html @@ -0,0 +1,10 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta http-equiv="refresh" content="0;URL=../../carboxyl/struct.Signal.html"> +</head> +<body> + <p>Redirecting to <a href="../../carboxyl/struct.Signal.html">../../carboxyl/struct.Signal.html</a>...</p> + <script>location.replace("../../carboxyl/struct.Signal.html" + location.search + location.hash);</script> +</body> +</html>
\ No newline at end of file diff --git a/carboxyl/signal/struct.SignalMut.html b/carboxyl/signal/struct.SignalMut.html new file mode 100644 index 0000000..9a55706 --- /dev/null +++ b/carboxyl/signal/struct.SignalMut.html @@ -0,0 +1,10 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta http-equiv="refresh" content="0;URL=../../carboxyl/struct.SignalMut.html"> +</head> +<body> + <p>Redirecting to <a href="../../carboxyl/struct.SignalMut.html">../../carboxyl/struct.SignalMut.html</a>...</p> + <script>location.replace("../../carboxyl/struct.SignalMut.html" + location.search + location.hash);</script> +</body> +</html>
\ No newline at end of file diff --git a/carboxyl/source/index.html b/carboxyl/source/index.html new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/carboxyl/source/index.html diff --git a/carboxyl/source/sidebar-items.js b/carboxyl/source/sidebar-items.js new file mode 100644 index 0000000..48333d3 --- /dev/null +++ b/carboxyl/source/sidebar-items.js @@ -0,0 +1 @@ +initSidebarItems({});
\ No newline at end of file diff --git a/carboxyl/stream/index.html b/carboxyl/stream/index.html new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/carboxyl/stream/index.html diff --git a/carboxyl/stream/sidebar-items.js b/carboxyl/stream/sidebar-items.js new file mode 100644 index 0000000..ccdbbe7 --- /dev/null +++ b/carboxyl/stream/sidebar-items.js @@ -0,0 +1 @@ +initSidebarItems({"struct":[["Sink","An event sink."],["Stream","A stream of events."]],"trait":[["BoxClone","Trait to wrap cloning of boxed values in a object-safe manner"]]});
\ No newline at end of file diff --git a/carboxyl/stream/struct.Sink.html b/carboxyl/stream/struct.Sink.html new file mode 100644 index 0000000..97044fd --- /dev/null +++ b/carboxyl/stream/struct.Sink.html @@ -0,0 +1,10 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta http-equiv="refresh" content="0;URL=../../carboxyl/struct.Sink.html"> +</head> +<body> + <p>Redirecting to <a href="../../carboxyl/struct.Sink.html">../../carboxyl/struct.Sink.html</a>...</p> + <script>location.replace("../../carboxyl/struct.Sink.html" + location.search + location.hash);</script> +</body> +</html>
\ No newline at end of file diff --git a/carboxyl/stream/struct.Stream.html b/carboxyl/stream/struct.Stream.html new file mode 100644 index 0000000..9c8a019 --- /dev/null +++ b/carboxyl/stream/struct.Stream.html @@ -0,0 +1,10 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta http-equiv="refresh" content="0;URL=../../carboxyl/struct.Stream.html"> +</head> +<body> + <p>Redirecting to <a href="../../carboxyl/struct.Stream.html">../../carboxyl/struct.Stream.html</a>...</p> + <script>location.replace("../../carboxyl/struct.Stream.html" + location.search + location.hash);</script> +</body> +</html>
\ No newline at end of file diff --git a/carboxyl/stream/trait.BoxClone.html b/carboxyl/stream/trait.BoxClone.html new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/carboxyl/stream/trait.BoxClone.html diff --git a/carboxyl/struct.Signal.html b/carboxyl/struct.Signal.html new file mode 100644 index 0000000..16abc52 --- /dev/null +++ b/carboxyl/struct.Signal.html @@ -0,0 +1,245 @@ +<!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 `Signal` struct in crate `carboxyl`."> + <meta name="keywords" content="rust, rustlang, rust-lang, Signal"> + + <title>carboxyl::Signal - 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: 'Signal', 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=''>Signal</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-2746' class='srclink' href='../src/carboxyl/signal.rs.html#154-159' title='goto source code'>[src]</a></span></h1> +<pre class='rust struct'>pub struct Signal<A> { + // some fields omitted +}</pre><div class='docblock'><p>A continuous signal that changes over time.</p> + +<p>Signals can be thought of as values that change over time. They have both a +continuous and a discrete component. This means that their current value is +defined by a function that can be called at any time. That function is only +evaluated on-demand, when the signal's current value is sampled. (This is +also called pull semantics in the literature on FRP.)</p> + +<p>In addition, the current function used to sample a signal may change +discretely in reaction to some event. For instance, it is possible to create +a signal from an event stream, by holding the last event occurence as the +current value of the stream.</p> + +<h1 id="algebraic-laws" class='section-header'><a + href="#algebraic-laws">Algebraic laws</a></h1> +<p>Signals come with some primitive methods to compose them with each other and +with streams. Some of these primitives give the signals an algebraic +structure.</p> + +<h2 id="functor" class='section-header'><a + href="#functor">Functor</a></h2> +<p>Signals form a functor under unary lifting. Thus, the following laws hold:</p> + +<ul> +<li>Preservation of identity: <code>lift!(|x| x, &a) == a</code>,</li> +<li>Function composition: <code>lift!(|x| g(f(x)), &a) == lift!(g, &lift!(f, &a))</code>.</li> +</ul> + +<h2 id="applicative-functor" class='section-header'><a + href="#applicative-functor">Applicative functor</a></h2> +<p>By extension, using the notion of a signal of a function, signals also +become an <a href="https://downloads.haskell.org/%7Eghc/latest/docs/html/libraries/base/Control-Applicative.html">applicative</a> using <code>Signal::new</code> as <code>pure</code> and +<code>|sf, sa| lift!(|f, a| f(a), &sf, &sa)</code> as <code><*></code>.</p> + +<p><em>TODO: Expand on this and replace the Haskell reference.</em></p> +</div><h2 id='methods'>Methods</h2><h3 class='impl'><code>impl<A: <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + 'static> <a class='struct' href='../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><A></code></h3><div class='impl-items'><h4 id='method.new' class='method'><code>fn <a href='#method.new' class='fnname'>new</a>(a: A) -> <a class='struct' href='../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><A></code></h4> +<div class='docblock'><p>Create a constant signal.</p> +</div><h4 id='method.sample' class='method'><code>fn <a href='#method.sample' class='fnname'>sample</a>(&self) -> A</code></h4> +<div class='docblock'><p>Sample the current value of the signal.</p> +</div></div><h3 class='impl'><code>impl<A: <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> <a class='struct' href='../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><A></code></h3><div class='impl-items'><h4 id='method.cyclic' class='method'><code>fn <a href='#method.cyclic' class='fnname'>cyclic</a><F>(def: F) -> <a class='struct' href='../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><A> <span class='where'>where F: <a class='trait' href='http://doc.rust-lang.org/nightly/core/ops/trait.FnOnce.html' title='core::ops::FnOnce'>FnOnce</a>(&<a class='struct' href='../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><A>) -> <a class='struct' href='../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><A></span></code></h4> +<div class='docblock'><p>Create a signal with a cyclic definition.</p> + +<p>The closure gets an undefined forward-declaration of a signal. It is +supposed to return a self-referential definition of the same signal.</p> + +<p>Sampling the forward-declared signal, before it is properly defined, +will cause a run-time panic.</p> + +<p>This pattern is useful to implement accumulators, counters and other +loops that depend on the sampling behaviour of a signal before a +transaction.</p> +</div><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>Combine the signal with a stream in a snapshot.</p> + +<p><code>snapshot</code> creates a new stream given a signal and a stream. Whenever +the input stream fires an event, the output stream fires an event +created from the signal's current value and that event using the +supplied function.</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>sink1</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'>sink2</span>: <span class='ident'>Sink</span><span class='op'><</span><span class='ident'>f64</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='kw-2'>mut</span> <span class='ident'>events</span> <span class='op'>=</span> <span class='ident'>sink1</span>.<span class='ident'>stream</span>().<span class='ident'>hold</span>(<span class='number'>1</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'>a</span>, <span class='ident'>b</span><span class='op'>|</span> (<span class='ident'>a</span>, <span class='ident'>b</span>)) + .<span class='ident'>events</span>(); + +<span class='comment'>// Updating its signal does not cause the snapshot to fire</span> +<span class='ident'>sink1</span>.<span class='ident'>send</span>(<span class='number'>4</span>); + +<span class='comment'>// However sending an event down the stream does</span> +<span class='ident'>sink2</span>.<span class='ident'>send</span>(<span class='number'>3.0</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>events</span>.<span class='ident'>next</span>(), <span class='prelude-val'>Some</span>((<span class='number'>4</span>, <span class='number'>3.0</span>))); +</pre> +</div></div><h3 class='impl'><code>impl<A: <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> <a class='struct' href='../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><<a class='struct' href='../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><A>></code></h3><div class='impl-items'><h4 id='method.switch' class='method'><code>fn <a href='#method.switch' class='fnname'>switch</a>(&self) -> <a class='struct' href='../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><A></code></h4> +<div class='docblock'><p>Switch between signals.</p> + +<p>This transforms a <code>Signal<Signal<A>></code> into a <code>Signal<A></code>. The nested +signal can be thought of as a representation of a switch between different +input signals, that allows one to change the structure of the dependency +graph at run-time. <code>switch</code> provides a way to access the inner value of +the currently active signal.</p> + +<p>The following example demonstrates how to use this to switch between two +input signals based on a <code>Button</code> event stream:</p> +<pre class='rust rust-example-rendered'> +<span class='comment'>// Button type</span> +<span class='attribute'>#[<span class='ident'>derive</span>(<span class='ident'>Clone</span>, <span class='ident'>Show</span>)]</span> +<span class='kw'>enum</span> <span class='ident'>Button</span> { <span class='ident'>A</span>, <span class='ident'>B</span> }; + +<span class='comment'>// The input sinks</span> +<span class='kw'>let</span> <span class='ident'>sink_a</span> <span class='op'>=</span> <span class='ident'>Sink</span>::<span class='op'><</span><span class='ident'>i32</span><span class='op'>></span>::<span class='ident'>new</span>(); +<span class='kw'>let</span> <span class='ident'>sink_b</span> <span class='op'>=</span> <span class='ident'>Sink</span>::<span class='op'><</span><span class='ident'>i32</span><span class='op'>></span>::<span class='ident'>new</span>(); + +<span class='comment'>// The button sink</span> +<span class='kw'>let</span> <span class='ident'>sink_button</span> <span class='op'>=</span> <span class='ident'>Sink</span>::<span class='op'><</span><span class='ident'>Button</span><span class='op'>></span>::<span class='ident'>new</span>(); + +<span class='comment'>// Create the output</span> +<span class='kw'>let</span> <span class='ident'>output</span> <span class='op'>=</span> { + + <span class='comment'>// Hold input sinks in a signal with some initials</span> + <span class='kw'>let</span> <span class='ident'>channel_a</span> <span class='op'>=</span> <span class='ident'>sink_a</span>.<span class='ident'>stream</span>().<span class='ident'>hold</span>(<span class='number'>1</span>); + <span class='kw'>let</span> <span class='ident'>channel_b</span> <span class='op'>=</span> <span class='ident'>sink_b</span>.<span class='ident'>stream</span>().<span class='ident'>hold</span>(<span class='number'>2</span>); + + <span class='comment'>// A trivial default channel used before any button event</span> + <span class='kw'>let</span> <span class='ident'>default_channel</span> <span class='op'>=</span> <span class='ident'>Sink</span>::<span class='ident'>new</span>().<span class='ident'>stream</span>().<span class='ident'>hold</span>(<span class='number'>0</span>); + + <span class='comment'>// Map button to the channel signals, hold with the default channel as</span> + <span class='comment'>// initial value and switch between the signals</span> + <span class='ident'>sink_button</span> + .<span class='ident'>stream</span>() + .<span class='ident'>map</span>(<span class='kw'>move</span> <span class='op'>|</span><span class='ident'>b</span><span class='op'>|</span> <span class='kw'>match</span> <span class='ident'>b</span> { + <span class='ident'>Button</span>::<span class='ident'>A</span> <span class='op'>=></span> <span class='ident'>channel_a</span>.<span class='ident'>clone</span>(), + <span class='ident'>Button</span>::<span class='ident'>B</span> <span class='op'>=></span> <span class='ident'>channel_b</span>.<span class='ident'>clone</span>(), + }) + .<span class='ident'>hold</span>(<span class='ident'>default_channel</span>) + .<span class='ident'>switch</span>() +}; + +<span class='comment'>// In the beginning, output will come from the default channel</span> +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>output</span>.<span class='ident'>sample</span>(), <span class='number'>0</span>); + +<span class='comment'>// Let's switch to channel A</span> +<span class='ident'>sink_button</span>.<span class='ident'>send</span>(<span class='ident'>Button</span>::<span class='ident'>A</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>output</span>.<span class='ident'>sample</span>(), <span class='number'>1</span>); + +<span class='comment'>// And to channel B</span> +<span class='ident'>sink_button</span>.<span class='ident'>send</span>(<span class='ident'>Button</span>::<span class='ident'>B</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>output</span>.<span class='ident'>sample</span>(), <span class='number'>2</span>); + +<span class='comment'>// The channels can change, too, of course</span> +<span class='kw'>for</span> <span class='ident'>k</span> <span class='kw'>in</span> <span class='number'>4</span>..<span class='number'>13</span> { + <span class='ident'>sink_b</span>.<span class='ident'>send</span>(<span class='ident'>k</span>); + <span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>output</span>.<span class='ident'>sample</span>(), <span class='ident'>k</span>); +} +<span class='ident'>sink_button</span>.<span class='ident'>send</span>(<span class='ident'>Button</span>::<span class='ident'>A</span>); +<span class='kw'>for</span> <span class='ident'>k</span> <span class='kw'>in</span> <span class='number'>21</span>..<span class='number'>77</span> { + <span class='ident'>sink_a</span>.<span class='ident'>send</span>(<span class='ident'>k</span>); + <span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>output</span>.<span class='ident'>sample</span>(), <span class='ident'>k</span>); +} +</pre> +</div></div><h2 id='implementations'>Trait Implementations</h2><h3 class='impl'><code>impl<A> <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> for <a class='struct' href='../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><A></code></h3><div class='impl-items'><h4 id='method.clone' class='method'><code>fn <a href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone' class='fnname'>clone</a>(&self) -> <a class='struct' href='../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><A></code></h4> +<h4 id='method.clone_from' class='method'><code>fn <a href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from' class='fnname'>clone_from</a>(&mut self, source: &Self)</code></h4> +</div><h3 class='impl'><code>impl<A: <a class='trait' href='http://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html' title='core::fmt::Debug'>Debug</a> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + 'static> <a class='trait' href='http://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html' title='core::fmt::Debug'>Debug</a> for <a class='struct' href='../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><A></code></h3><div class='impl-items'><h4 id='method.fmt' class='method'><code>fn <a href='http://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#method.fmt' class='fnname'>fmt</a>(&self, fmt: &mut <a class='struct' href='http://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html' title='core::fmt::Formatter'>Formatter</a>) -> <a class='enum' href='http://doc.rust-lang.org/nightly/core/result/enum.Result.html' title='core::result::Result'>Result</a><<a href='http://doc.rust-lang.org/nightly/std/primitive.tuple.html'>()</a>, <a class='struct' href='http://doc.rust-lang.org/nightly/core/fmt/struct.Error.html' title='core::fmt::Error'>Error</a>></code></h4> +</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 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 diff --git a/carboxyl/struct.Sink.html b/carboxyl/struct.Sink.html new file mode 100644 index 0000000..742e070 --- /dev/null +++ b/carboxyl/struct.Sink.html @@ -0,0 +1,172 @@ +<!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 `Sink` struct in crate `carboxyl`."> + <meta name="keywords" content="rust, rustlang, rust-lang, Sink"> + + <title>carboxyl::Sink - 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: 'Sink', 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=''>Sink</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-1166' class='srclink' href='../src/carboxyl/stream.rs.html#62-64' title='goto source code'>[src]</a></span></h1> +<pre class='rust struct'>pub struct Sink<A> { + // some fields omitted +}</pre><div class='docblock'><p>An event sink.</p> + +<p>This primitive is a way of generating streams of events. One can send +input values into a sink and generate a stream that fires all these inputs +as events:</p> +<pre class='rust rust-example-rendered'> +<span class='comment'>// A new sink</span> +<span class='kw'>let</span> <span class='ident'>sink</span> <span class='op'>=</span> <span class='ident'>Sink</span>::<span class='ident'>new</span>(); + +<span class='comment'>// Make an iterator over a stream.</span> +<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>events</span> <span class='op'>=</span> <span class='ident'>sink</span>.<span class='ident'>stream</span>().<span class='ident'>events</span>(); + +<span class='comment'>// Send a value into the sink</span> +<span class='ident'>sink</span>.<span class='ident'>send</span>(<span class='number'>5</span>); + +<span class='comment'>// The stream</span> +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>events</span>.<span class='ident'>next</span>(), <span class='prelude-val'>Some</span>(<span class='number'>5</span>)); +</pre> + +<p>You can also feed a sink with an iterator:</p> +<pre class='rust rust-example-rendered'> +<span class='ident'>sink</span>.<span class='ident'>feed</span>(<span class='number'>20</span>..<span class='number'>40</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>events</span>.<span class='ident'>take</span>(<span class='number'>4</span>).<span class='ident'>collect</span>::<span class='op'><</span><span class='ident'>Vec</span><span class='op'><</span>_<span class='op'>>></span>(), <span class='macro'>vec</span><span class='macro'>!</span>[<span class='number'>20</span>, <span class='number'>21</span>, <span class='number'>22</span>, <span class='number'>23</span>]); +</pre> + +<h1 id="asynchronous-calls" class='section-header'><a + href="#asynchronous-calls">Asynchronous calls</a></h1> +<p>It is possible to send events into the sink asynchronously using the methods +<code>send_async</code> and <code>feed_async</code>. Note though, that this will void some +guarantees on the order of events. In the following example, it is unclear, +which event is the first in the stream:</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>sink</span> <span class='op'>=</span> <span class='ident'>Sink</span>::<span class='ident'>new</span>(); +<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>events</span> <span class='op'>=</span> <span class='ident'>sink</span>.<span class='ident'>stream</span>().<span class='ident'>events</span>(); +<span class='ident'>sink</span>.<span class='ident'>send_async</span>(<span class='number'>13</span>); +<span class='ident'>sink</span>.<span class='ident'>send_async</span>(<span class='number'>22</span>); +<span class='kw'>let</span> <span class='ident'>first</span> <span class='op'>=</span> <span class='ident'>events</span>.<span class='ident'>next</span>().<span class='ident'>unwrap</span>(); +<span class='macro'>assert</span><span class='macro'>!</span>(<span class='ident'>first</span> <span class='op'>==</span> <span class='number'>13</span> <span class='op'>||</span> <span class='ident'>first</span> <span class='op'>==</span> <span class='number'>22</span>); +</pre> + +<p><code>feed_async</code> provides a workaround, as it preserves the order of events from +the iterator. However, any event sent into the sink after a call to it, may +come at any point between the iterator events.</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>> <a class='struct' href='../carboxyl/struct.Sink.html' title='carboxyl::Sink'>Sink</a><A></code></h3><div class='impl-items'><h4 id='method.new' class='method'><code>fn <a href='#method.new' class='fnname'>new</a>() -> <a class='struct' href='../carboxyl/struct.Sink.html' title='carboxyl::Sink'>Sink</a><A></code></h4> +<div class='docblock'><p>Create a new sink.</p> +</div><h4 id='method.stream' class='method'><code>fn <a href='#method.stream' class='fnname'>stream</a>(&self) -> <a class='struct' href='../carboxyl/struct.Stream.html' title='carboxyl::Stream'>Stream</a><A></code></h4> +<div class='docblock'><p>Generate a stream that fires all events sent into the sink.</p> +</div></div><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> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + 'static> <a class='struct' href='../carboxyl/struct.Sink.html' title='carboxyl::Sink'>Sink</a><A></code></h3><div class='impl-items'><h4 id='method.send_async' class='method'><code>fn <a href='#method.send_async' class='fnname'>send_async</a>(&self, a: A)</code></h4> +<div class='docblock'><p>Asynchronous send.</p> + +<p>Same as <code>send</code>, but it spawns a new thread to process the updates to +dependent streams and signals.</p> +</div><h4 id='method.feed' class='method'><code>fn <a href='#method.feed' class='fnname'>feed</a><I: <a class='trait' href='http://doc.rust-lang.org/nightly/core/iter/trait.IntoIterator.html' title='core::iter::IntoIterator'>IntoIterator</a><Item=A>>(&self, iterator: I)</code></h4> +<div class='docblock'><p>Feed values from an iterator into the sink.</p> + +<p>This method feeds events into the sink from an iterator.</p> +</div><h4 id='method.feed_async' class='method'><code>fn <a href='#method.feed_async' class='fnname'>feed_async</a><I: <a class='trait' href='http://doc.rust-lang.org/nightly/core/iter/trait.IntoIterator.html' title='core::iter::IntoIterator'>IntoIterator</a><Item=A> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/marker/trait.Send.html' title='core::marker::Send'>Send</a> + 'static>(&self, iterator: I)</code></h4> +<div class='docblock'><p>Asynchronous feed.</p> + +<p>This is the same as <code>feed</code>, but it does not block, since it spawns the +feeding as a new task. This is useful, if the provided iterator is large +or even infinite (e.g. an I/O event loop).</p> +</div><h4 id='method.send' class='method'><code>fn <a href='#method.send' class='fnname'>send</a>(&self, a: A)</code></h4> +<div class='docblock'><p>Send a value into the sink.</p> + +<p>When a value is sent into the sink, an event is fired in all dependent +streams.</p> +</div></div><h2 id='implementations'>Trait Implementations</h2><h3 class='impl'><code>impl<A> <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> for <a class='struct' href='../carboxyl/struct.Sink.html' title='carboxyl::Sink'>Sink</a><A></code></h3><div class='impl-items'><h4 id='method.clone' class='method'><code>fn <a href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone' class='fnname'>clone</a>(&self) -> <a class='struct' href='../carboxyl/struct.Sink.html' title='carboxyl::Sink'>Sink</a><A></code></h4> +<h4 id='method.clone_from' class='method'><code>fn <a href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from' class='fnname'>clone_from</a>(&mut self, source: &Self)</code></h4> +</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 diff --git a/carboxyl/struct.Stream.html b/carboxyl/struct.Stream.html new file mode 100644 index 0000000..e51f5ac --- /dev/null +++ b/carboxyl/struct.Stream.html @@ -0,0 +1,304 @@ +<!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 `Stream` struct in crate `carboxyl`."> + <meta name="keywords" content="rust, rustlang, rust-lang, Stream"> + + <title>carboxyl::Stream - 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: 'Stream', 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=''>Stream</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-1394' class='srclink' href='../src/carboxyl/stream.rs.html#186-190' title='goto source code'>[src]</a></span></h1> +<pre class='rust struct'>pub struct Stream<A> { + // some fields omitted +}</pre><div class='docblock'><p>A stream of events.</p> + +<p>Conceptually a stream can be thought of as a series of discrete events that +occur at specific times. They are ordered by a transaction system. This +means that firings of disjoint events can not interfere with each other. The +consequences of one event are atomically reflected in dependent quantities.</p> + +<p>Streams provide a number of primitive operations. These can be used to +compose streams and combine them with signals. For instance, streams can be +mapped over with a function, merged with another stream of the same type or +filtered by some predicate.</p> + +<h1 id="algebraic-laws" class='section-header'><a + href="#algebraic-laws">Algebraic laws</a></h1> +<p>Furthermore, streams satisfy certain algebraic properties that are useful to +reason about them.</p> + +<h2 id="monoid" class='section-header'><a + href="#monoid">Monoid</a></h2> +<p>For once, streams of the same type form a <strong>monoid</strong> under merging. The +neutral element in this context is <code>Stream::never()</code>. So the following laws +always hold for streams <code>a</code>, <code>b</code> and <code>c</code> of the same type:</p> + +<ul> +<li>Left identity: <code>Stream::never().merge(&a) == a</code>,</li> +<li>Right identity: <code>a.merge(&Stream::never()) == a</code>,</li> +<li>Associativity: <code>a.merge(&b).merge(&c) == a.merge(&b.merge(&c))</code>.</li> +</ul> + +<p><em>Note that equality in this context is not actually implemented as such, +since comparing two (potentially infinite) streams is a prohibitive +operation. Instead, the expressions above can be used interchangably and +behave identically.</em></p> + +<h2 id="functor" class='section-header'><a + href="#functor">Functor</a></h2> +<p>Under the mapping operation streams also become a functor. A functor is a +generic type like <code>Stream</code> with some mapping operation that takes a function +<code>Fn(A) -> B</code> to map a <code>Stream<A></code> to a <code>Stream<B></code>. Algebraically it +satisfies the following laws:</p> + +<ul> +<li>The identity function is preserved: <code>a.map(|x| x) == a</code>,</li> +<li>Function composition is respected: <code>a.map(f).map(g) == a.map(|x| g(f(x)))</code>.</li> +</ul> +</div><h2 id='methods'>Methods</h2><h3 class='impl'><code>impl<A: <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> <a class='struct' href='../carboxyl/struct.Stream.html' title='carboxyl::Stream'>Stream</a><A></code></h3><div class='impl-items'><h4 id='method.never' class='method'><code>fn <a href='#method.never' class='fnname'>never</a>() -> <a class='struct' href='../carboxyl/struct.Stream.html' title='carboxyl::Stream'>Stream</a><A></code></h4> +<div class='docblock'><p>Create a stream that never fires. This can be useful in certain +situations, where a stream is logically required, but no events are +expected.</p> +</div><h4 id='method.map' class='method'><code>fn <a href='#method.map' class='fnname'>map</a><B, F>(&self, f: F) -> <a class='struct' href='../carboxyl/struct.Stream.html' title='carboxyl::Stream'>Stream</a><B> <span class='where'>where B: <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> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</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 + <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>Map the stream to another stream using a function.</p> + +<p><code>map</code> applies a function to every event fired in this stream to create a +new stream of type <code>B</code>.</p> +<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='kw-2'>mut</span> <span class='ident'>events</span> <span class='op'>=</span> <span class='ident'>sink</span>.<span class='ident'>stream</span>().<span class='ident'>map</span>(<span class='op'>|</span><span class='ident'>x</span><span class='op'>|</span> <span class='ident'>x</span> <span class='op'>+</span> <span class='number'>4</span>).<span class='ident'>events</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'>events</span>.<span class='ident'>next</span>(), <span class='prelude-val'>Some</span>(<span class='number'>7</span>)); +</pre> +</div><h4 id='method.filter' class='method'><code>fn <a href='#method.filter' class='fnname'>filter</a><F>(&self, f: F) -> <a class='struct' href='../carboxyl/struct.Stream.html' title='carboxyl::Stream'>Stream</a><A> <span class='where'>where F: <a class='trait' href='http://doc.rust-lang.org/nightly/core/ops/trait.Fn.html' title='core::ops::Fn'>Fn</a>(&A) -> <a href='http://doc.rust-lang.org/nightly/std/primitive.bool.html'>bool</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</span></code></h4> +<div class='docblock'><p>Filter a stream according to a predicate.</p> + +<p><code>filter</code> creates a new stream that only fires those events from the +original stream that satisfy the predicate.</p> +<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='kw-2'>mut</span> <span class='ident'>events</span> <span class='op'>=</span> <span class='ident'>sink</span>.<span class='ident'>stream</span>() + .<span class='ident'>filter</span>(<span class='op'>|</span><span class='kw-2'>&</span><span class='ident'>x</span><span class='op'>|</span> (<span class='ident'>x</span> <span class='op'>>=</span> <span class='number'>4</span>) <span class='op'>&&</span> (<span class='ident'>x</span> <span class='op'><=</span> <span class='number'>10</span>)) + .<span class='ident'>events</span>(); +<span class='ident'>sink</span>.<span class='ident'>send</span>(<span class='number'>2</span>); <span class='comment'>// won't arrive</span> +<span class='ident'>sink</span>.<span class='ident'>send</span>(<span class='number'>5</span>); <span class='comment'>// will arrive</span> +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>events</span>.<span class='ident'>next</span>(), <span class='prelude-val'>Some</span>(<span class='number'>5</span>)); +</pre> +</div><h4 id='method.filter_map' class='method'><code>fn <a href='#method.filter_map' class='fnname'>filter_map</a><B, F>(&self, f: F) -> <a class='struct' href='../carboxyl/struct.Stream.html' title='carboxyl::Stream'>Stream</a><B> <span class='where'>where B: <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> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</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) -> <a class='enum' href='http://doc.rust-lang.org/nightly/core/option/enum.Option.html' title='core::option::Option'>Option</a><B> + <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>Both filter and map a stream.</p> + +<p>This is equivalent to <code>.map(f).filter_some()</code>.</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>sink</span> <span class='op'>=</span> <span class='ident'>Sink</span>::<span class='ident'>new</span>(); +<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>events</span> <span class='op'>=</span> <span class='ident'>sink</span>.<span class='ident'>stream</span>() + .<span class='ident'>filter_map</span>(<span class='op'>|</span><span class='ident'>i</span><span class='op'>|</span> <span class='kw'>if</span> <span class='ident'>i</span> <span class='op'>></span> <span class='number'>3</span> { <span class='prelude-val'>Some</span>(<span class='ident'>i</span> <span class='op'>+</span> <span class='number'>2</span>) } <span class='kw'>else</span> { <span class='prelude-val'>None</span> }) + .<span class='ident'>events</span>(); +<span class='ident'>sink</span>.<span class='ident'>send</span>(<span class='number'>2</span>); +<span class='ident'>sink</span>.<span class='ident'>send</span>(<span class='number'>4</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>events</span>.<span class='ident'>next</span>(), <span class='prelude-val'>Some</span>(<span class='number'>6</span>)); +</pre> +</div><h4 id='method.merge' class='method'><code>fn <a href='#method.merge' class='fnname'>merge</a>(&self, other: &<a class='struct' href='../carboxyl/struct.Stream.html' title='carboxyl::Stream'>Stream</a><A>) -> <a class='struct' href='../carboxyl/struct.Stream.html' title='carboxyl::Stream'>Stream</a><A></code></h4> +<div class='docblock'><p>Merge with another stream.</p> + +<p><code>merge</code> takes two streams and creates a new stream that fires events +from both input streams.</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>sink_1</span> <span class='op'>=</span> <span class='ident'>Sink</span>::<span class='op'><</span><span class='ident'>i32</span><span class='op'>></span>::<span class='ident'>new</span>(); +<span class='kw'>let</span> <span class='ident'>sink_2</span> <span class='op'>=</span> <span class='ident'>Sink</span>::<span class='op'><</span><span class='ident'>i32</span><span class='op'>></span>::<span class='ident'>new</span>(); +<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>events</span> <span class='op'>=</span> <span class='ident'>sink_1</span>.<span class='ident'>stream</span>().<span class='ident'>merge</span>(<span class='kw-2'>&</span><span class='ident'>sink_2</span>.<span class='ident'>stream</span>()).<span class='ident'>events</span>(); +<span class='ident'>sink_1</span>.<span class='ident'>send</span>(<span class='number'>2</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>events</span>.<span class='ident'>next</span>(), <span class='prelude-val'>Some</span>(<span class='number'>2</span>)); +<span class='ident'>sink_2</span>.<span class='ident'>send</span>(<span class='number'>4</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>events</span>.<span class='ident'>next</span>(), <span class='prelude-val'>Some</span>(<span class='number'>4</span>)); +</pre> +</div><h4 id='method.coalesce' class='method'><code>fn <a href='#method.coalesce' class='fnname'>coalesce</a><F>(&self, f: F) -> <a class='struct' href='../carboxyl/struct.Stream.html' title='carboxyl::Stream'>Stream</a><A> <span class='where'>where F: <a class='trait' href='http://doc.rust-lang.org/nightly/core/ops/trait.Fn.html' title='core::ops::Fn'>Fn</a>(A, A) -> 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</span></code></h4> +<div class='docblock'><p>Coalesce multiple event firings within the same transaction into a +single event.</p> + +<p>The function should ideally commute, as the order of events within a +transaction is not well-defined.</p> +</div><h4 id='method.hold' class='method'><code>fn <a href='#method.hold' class='fnname'>hold</a>(&self, initial: A) -> <a class='struct' href='../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><A></code></h4> +<div class='docblock'><p>Hold an event in a signal.</p> + +<p>The resulting signal <code>hold</code>s the value of the last event fired by the +stream.</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>sink</span> <span class='op'>=</span> <span class='ident'>Sink</span>::<span class='ident'>new</span>(); +<span class='kw'>let</span> <span class='ident'>signal</span> <span class='op'>=</span> <span class='ident'>sink</span>.<span class='ident'>stream</span>().<span class='ident'>hold</span>(<span class='number'>0</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>signal</span>.<span class='ident'>sample</span>(), <span class='number'>0</span>); +<span class='ident'>sink</span>.<span class='ident'>send</span>(<span class='number'>2</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>signal</span>.<span class='ident'>sample</span>(), <span class='number'>2</span>); +</pre> +</div><h4 id='method.events' class='method'><code>fn <a href='#method.events' class='fnname'>events</a>(&self) -> Events<A></code></h4> +<div class='docblock'><p>A blocking iterator over the stream.</p> +</div><h4 id='method.scan' class='method'><code>fn <a href='#method.scan' class='fnname'>scan</a><B, F>(&self, initial: B, f: F) -> <a class='struct' href='../carboxyl/struct.Signal.html' title='carboxyl::Signal'>Signal</a><B> <span class='where'>where B: <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> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + 'static, F: <a class='trait' href='http://doc.rust-lang.org/nightly/core/ops/trait.Fn.html' title='core::ops::Fn'>Fn</a>(B, A) -> B + <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>Scan a stream and accumulate its event firings in a signal.</p> + +<p>Starting at some initial value, each new event changes the value of the +resulting signal as prescribed by the supplied function.</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>sink</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</span>(<span class='number'>0</span>, <span class='op'>|</span><span class='ident'>a</span>, <span class='ident'>b</span><span class='op'>|</span> <span class='ident'>a</span> <span class='op'>+</span> <span class='ident'>b</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>sum</span>.<span class='ident'>sample</span>(), <span class='number'>0</span>); +<span class='ident'>sink</span>.<span class='ident'>send</span>(<span class='number'>2</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>sum</span>.<span class='ident'>sample</span>(), <span class='number'>2</span>); +<span class='ident'>sink</span>.<span class='ident'>send</span>(<span class='number'>4</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>sum</span>.<span class='ident'>sample</span>(), <span class='number'>6</span>); +</pre> +</div><h4 id='method.scan_mut' class='method'><code>fn <a href='#method.scan_mut' class='fnname'>scan_mut</a><B, F>(&self, initial: B, f: F) -> <a class='struct' href='../carboxyl/struct.SignalMut.html' title='carboxyl::SignalMut'>SignalMut</a><B> <span class='where'>where B: <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>(&mut B, 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</span></code></h4> +<div class='docblock'><p>Scan a stream and accumulate its event firings in some mutable state.</p> + +<p>Semantically this is equivalent to <code>scan</code>. However, it allows one to use +a non-Clone type as an accumulator and update it with efficient in-place +operations.</p> + +<p>The resulting <code>SignalMut</code> does have a slightly different API from a +regular <code>Signal</code> as it does not allow clones.</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='ident'>combine</span>(<span class='kw-2'>&</span><span class='ident'>Signal</span>::<span class='ident'>new</span>(()), <span class='op'>|</span><span class='ident'>sum</span>, ()<span class='op'>|</span> <span class='op'>*</span><span class='ident'>sum</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>sum</span>.<span class='ident'>sample</span>(), <span class='number'>0</span>); +<span class='ident'>sink</span>.<span class='ident'>send</span>(<span class='number'>2</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>sum</span>.<span class='ident'>sample</span>(), <span class='number'>2</span>); +<span class='ident'>sink</span>.<span class='ident'>send</span>(<span class='number'>4</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>sum</span>.<span class='ident'>sample</span>(), <span class='number'>6</span>); +</pre> +</div></div><h3 class='impl'><code>impl<A: <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> <a class='struct' href='../carboxyl/struct.Stream.html' title='carboxyl::Stream'>Stream</a><<a class='enum' href='http://doc.rust-lang.org/nightly/core/option/enum.Option.html' title='core::option::Option'>Option</a><A>></code></h3><div class='impl-items'><h4 id='method.filter_some' class='method'><code>fn <a href='#method.filter_some' class='fnname'>filter_some</a>(&self) -> <a class='struct' href='../carboxyl/struct.Stream.html' title='carboxyl::Stream'>Stream</a><A></code></h4> +<div class='docblock'><p>Filter a stream of options.</p> + +<p><code>filter_some</code> creates a new stream that only fires the unwrapped +<code>Some(…)</code> events from the original stream omitting any <code>None</code> events.</p> +<pre class='rust rust-example-rendered'> +<span class='kw'>let</span> <span class='ident'>sink</span> <span class='op'>=</span> <span class='ident'>Sink</span>::<span class='ident'>new</span>(); +<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>events</span> <span class='op'>=</span> <span class='ident'>sink</span>.<span class='ident'>stream</span>().<span class='ident'>filter_some</span>().<span class='ident'>events</span>(); +<span class='ident'>sink</span>.<span class='ident'>send</span>(<span class='prelude-val'>None</span>); <span class='comment'>// won't arrive</span> +<span class='ident'>sink</span>.<span class='ident'>send</span>(<span class='prelude-val'>Some</span>(<span class='number'>5</span>)); <span class='comment'>// will arrive</span> +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>events</span>.<span class='ident'>next</span>(), <span class='prelude-val'>Some</span>(<span class='number'>5</span>)); +</pre> +</div></div><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> + <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> + 'static> <a class='struct' href='../carboxyl/struct.Stream.html' title='carboxyl::Stream'>Stream</a><<a class='struct' href='../carboxyl/struct.Stream.html' title='carboxyl::Stream'>Stream</a><A>></code></h3><div class='impl-items'><h4 id='method.switch' class='method'><code>fn <a href='#method.switch' class='fnname'>switch</a>(&self) -> <a class='struct' href='../carboxyl/struct.Stream.html' title='carboxyl::Stream'>Stream</a><A></code></h4> +<div class='docblock'><p>Switch between streams.</p> + +<p>This takes a stream of streams and maps it to a new stream, which fires +all events from the most recent stream fired into it.</p> + +<h1 id="example" class='section-header'><a + href="#example">Example</a></h1><pre class='rust rust-example-rendered'> +<span class='comment'>// Create sinks</span> +<span class='kw'>let</span> <span class='ident'>stream_sink</span>: <span class='ident'>Sink</span><span class='op'><</span><span class='ident'>Stream</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'>sink1</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'>sink2</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='comment'>// Switch and listen</span> +<span class='kw'>let</span> <span class='ident'>switched</span> <span class='op'>=</span> <span class='ident'>stream_sink</span>.<span class='ident'>stream</span>().<span class='ident'>switch</span>(); +<span class='kw'>let</span> <span class='kw-2'>mut</span> <span class='ident'>events</span> <span class='op'>=</span> <span class='ident'>switched</span>.<span class='ident'>events</span>(); + +<span class='comment'>// Should not receive events from either sink</span> +<span class='ident'>sink1</span>.<span class='ident'>send</span>(<span class='number'>1</span>); <span class='ident'>sink2</span>.<span class='ident'>send</span>(<span class='number'>2</span>); + +<span class='comment'>// Now switch to sink 2</span> +<span class='ident'>stream_sink</span>.<span class='ident'>send</span>(<span class='ident'>sink2</span>.<span class='ident'>stream</span>()); +<span class='ident'>sink1</span>.<span class='ident'>send</span>(<span class='number'>3</span>); <span class='ident'>sink2</span>.<span class='ident'>send</span>(<span class='number'>4</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>events</span>.<span class='ident'>next</span>(), <span class='prelude-val'>Some</span>(<span class='number'>4</span>)); + +<span class='comment'>// And then to sink 1</span> +<span class='ident'>stream_sink</span>.<span class='ident'>send</span>(<span class='ident'>sink1</span>.<span class='ident'>stream</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'>6</span>); +<span class='macro'>assert_eq</span><span class='macro'>!</span>(<span class='ident'>events</span>.<span class='ident'>next</span>(), <span class='prelude-val'>Some</span>(<span class='number'>5</span>)); +</pre> +</div></div><h2 id='implementations'>Trait Implementations</h2><h3 class='impl'><code>impl<A> <a class='trait' href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html' title='core::clone::Clone'>Clone</a> for <a class='struct' href='../carboxyl/struct.Stream.html' title='carboxyl::Stream'>Stream</a><A></code></h3><div class='impl-items'><h4 id='method.clone' class='method'><code>fn <a href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone' class='fnname'>clone</a>(&self) -> <a class='struct' href='../carboxyl/struct.Stream.html' title='carboxyl::Stream'>Stream</a><A></code></h4> +<h4 id='method.clone_from' class='method'><code>fn <a href='http://doc.rust-lang.org/nightly/core/clone/trait.Clone.html#method.clone_from' class='fnname'>clone_from</a>(&mut self, source: &Self)</code></h4> +</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 diff --git a/carboxyl/transaction/index.html b/carboxyl/transaction/index.html new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/carboxyl/transaction/index.html diff --git a/carboxyl/transaction/sidebar-items.js b/carboxyl/transaction/sidebar-items.js new file mode 100644 index 0000000..48333d3 --- /dev/null +++ b/carboxyl/transaction/sidebar-items.js @@ -0,0 +1 @@ +initSidebarItems({});
\ No newline at end of file |