futures_signals/
lib.rs

1#![recursion_limit="128"]
2#![warn(unreachable_pub)]
3// missing_docs
4#![deny(warnings, missing_debug_implementations, macro_use_extern_crate)]
5
6///! It is *very highly* recommended to read the tutorial.
7///! It explains all of the concepts you will need to use Signals effectively.
8
9#[cfg(test)]
10extern crate futures_executor;
11
12// TODO should this be hidden from the docs ?
13#[doc(hidden)]
14#[macro_use]
15pub mod internal;
16
17#[doc(hidden)]
18pub use gensym::gensym as __internal_gensym;
19
20pub mod signal;
21pub mod signal_vec;
22pub mod signal_map;
23
24mod atomic;
25mod future;
26pub use crate::future::{cancelable_future, CancelableFutureHandle, CancelableFuture};
27
28
29/// # Tutorial
30///
31/// This tutorial is long, but it's intended to explain everything you need to
32/// know in order to use Signals.
33///
34/// It is highly recommended to read through all of it.
35///
36/// ## `Mutable`
37///
38/// Before I can fully explain Signals, first I have to explain [`Mutable`](../signal/struct.Mutable.html):
39///
40/// ```rust
41/// use futures_signals::signal::Mutable;
42///
43/// let my_state = Mutable::new(5);
44/// ```
45///
46/// The above example creates a new `Mutable` with an initial value of `5`.
47///
48/// `Mutable` is very similar to [`Arc`](https://doc.rust-lang.org/std/sync/struct.Arc.html) + [`RwLock`](https://doc.rust-lang.org/std/sync/struct.RwLock.html):
49///
50/// * It implements [`Send`](https://doc.rust-lang.org/std/marker/trait.Send.html) and
51///    [`Sync`](https://doc.rust-lang.org/std/marker/trait.Sync.html),
52///    so it can be sent and used between multiple threads.
53/// * It implements [`Clone`](https://doc.rust-lang.org/std/clone/trait.Clone.html),
54///    which will create a new reference to the same `Mutable` (just like [`Arc`](https://doc.rust-lang.org/std/sync/struct.Arc.html)).
55/// * You can retrieve the current value.
56/// * You can change the current value.
57///
58/// Let's see it in action:
59///
60/// ```rust
61/// # use futures_signals::signal::Mutable;
62/// # let my_state = Mutable::new(5);
63/// #
64/// // Acquires a mutable lock on my_state
65/// let mut lock = my_state.lock_mut();
66///
67/// assert_eq!(*lock, 5);
68///
69/// // Changes the current value of my_state to 10
70/// *lock = 10;
71///
72/// assert_eq!(*lock, 10);
73/// ```
74///
75/// ## `for_each`
76///
77/// However, if that was all `Mutable` could do, it wouldn't be very useful,
78/// because `RwLock` already exists!
79///
80/// The major difference between `Mutable` and `RwLock` is that it is possible
81/// to be efficiently notified whenever the `Mutable` changes:
82///
83/// ```rust
84/// # use futures_signals::signal::Mutable;
85/// # let my_state = Mutable::new(10);
86/// #
87/// use futures_signals::signal::SignalExt;
88///
89/// let future = my_state.signal().for_each(|value| {
90///     // This code is run for the current value of my_state,
91///     // and also every time my_state changes
92///     println!("{}", value);
93///     async {}
94/// });
95/// ```
96///
97/// This is how the [`for_each`](../signal/trait.SignalExt.html#method.for_each) method works:
98///
99/// 1. It returns a [`Future`](https://doc.rust-lang.org/std/future/trait.Future.html).
100///
101/// 2. When that [`Future`](https://doc.rust-lang.org/std/future/trait.Future.html)
102///    is spawned, it will call the `|value| { ... }` closure with the *current
103///    value* of `my_state` (which in this case is `10`).
104///
105/// 3. Then whenever `my_state` changes it will call the closure again with the new value.
106///
107/// This can be used for all sorts of things, such as automatically updating
108/// your GUI or database whenever the `Signal` changes.
109///
110/// Just like [`Future`](https://doc.rust-lang.org/std/future/trait.Future.html) and
111/// [`Stream`](https://docs.rs/futures/^0.3.15/futures/stream/trait.Stream.html),
112/// when you create a `Signal` it does not actually do anything until it is spawned.
113///
114/// In order to spawn a `Signal` you first use the `for_each` method (as shown
115/// above) to convert it into a `Future`, and then you spawn that `Future`.
116///
117/// There are many ways to spawn a `Future`:
118///
119/// * [`block_on(future)`](https://docs.rs/futures/^0.3.15/futures/executor/fn.block_on.html)
120/// * [`tokio::spawn(future)`](https://docs.rs/tokio/^1.6.1/tokio/task/fn.spawn.html)
121/// * [`task::spawn(future)`](https://docs.rs/async-std/^1.9.0/async_std/task/fn.spawn.html)
122/// * [`spawn_local(future)`](https://docs.rs/wasm-bindgen-futures/^0.4.24/wasm_bindgen_futures/fn.spawn_local.html)
123///
124/// And many more! Because `for_each` returns a normal `Future`, anything that
125/// can spawn a `Future` can also spawn a `Signal`.
126///
127/// That also means you can use all of the [`FutureExt`](https://docs.rs/futures/^0.3.15/futures/future/trait.FutureExt.html)
128/// methods on it as well.
129///
130/// ## `to_stream`
131///
132/// If you need more control, you can use [`to_stream`](../signal/trait.SignalExt.html#method.to_stream) instead:
133///
134/// ```rust
135/// # use futures_signals::signal::Mutable;
136/// # let my_state = Mutable::new(10);
137/// # use futures_signals::signal::SignalExt;
138/// #
139/// let stream = my_state.signal().to_stream();
140/// ```
141///
142/// This returns a [`Stream`](https://docs.rs/futures/^0.3.15/futures/stream/trait.Stream.html)
143/// of values (starting with the current value of `my_state`, and then followed
144/// by the changes to `my_state`).
145///
146/// You can use all of the [`StreamExt`](https://docs.rs/futures/^0.3.15/futures/stream/trait.StreamExt.html)
147/// methods on it, just like with any other
148/// [`Stream`](https://docs.rs/futures/^0.3.15/futures/stream/trait.Stream.html).
149///
150/// ## `signal`
151///
152/// You might be wondering why you have to call the `signal()` method: why can't
153/// you just use the `Mutable` directly?
154///
155/// There are actually three different methods, which you can use depending on
156/// your needs:
157///
158/// 1. [`signal()`](../signal/struct.ReadOnlyMutable.html#method.signal) is the
159///    most convenient but it requires the value to be [`Copy`](https://doc.rust-lang.org/std/marker/trait.Copy.html).
160///
161/// 2. [`signal_cloned()`](../signal/struct.ReadOnlyMutable.html#method.signal_cloned)
162///    requires the value to be [`Clone`](https://doc.rust-lang.org/std/clone/trait.Clone.html).
163///
164/// 3. [`signal_ref(|x| { ... })`](../signal/struct.ReadOnlyMutable.html#method.signal_ref)
165///    gives the closure a `&` reference to the value, so the value doesn't need
166///    to be [`Copy`](https://doc.rust-lang.org/std/marker/trait.Copy.html) or
167///    [`Clone`](https://doc.rust-lang.org/std/clone/trait.Clone.html), but
168///    instead the value is determined by the closure.
169///
170///    This is the most flexible and also the fastest, but it is the longest and
171///    most cumbersome to use.
172///
173/// In addition, it is possible to call the `signal` methods multiple times
174/// (and mix-and-match them):
175///
176/// ```rust
177/// # use futures_signals::signal::Mutable;
178/// # let my_state = Mutable::new(10);
179/// #
180/// let signal1 = my_state.signal();
181/// let signal2 = my_state.signal();
182/// let signal3 = my_state.signal_cloned();
183/// let signal4 = my_state.signal_ref(|x| *x + 10);
184/// ```
185///
186/// When the `Mutable` changes, *all* of its `Signal`s are notified.
187///
188/// This turns out to be very useful in practice: it's common to put your
189/// program's state inside of a global `Mutable` (or multiple `Mutable`s) and
190/// then share it in various places throughout your program.
191///
192/// Lastly, there is a big difference between `Mutable` and `Signal`:
193/// a `Signal` can only be notified when its value changes. However, a `Mutable`
194/// can do a lot more than that, because it can retrieve the current value, and
195/// it can also set the value.
196///
197/// ## `Signal`
198///
199/// Now that I've fully explained `Mutable`, I can finally explain [`Signal`](../signal/trait.Signal.html).
200///
201/// A `Signal` is an efficient zero-cost value which changes over time, and you
202/// can be efficiently notified when it changes.
203///
204/// Just like [`Future`](https://doc.rust-lang.org/std/future/trait.Future.html)
205/// and [`Stream`](https://docs.rs/futures/^0.3.15/futures/stream/trait.Stream.html),
206/// `Signal`s are inlined and compiled into a very efficient state machine.
207/// Most of the time they are fully stack allocated (*no* heap allocation).
208///
209/// And in the rare cases that they heap allocate they only do it *once*, when
210/// the `Signal` is created, not while the `Signal` is running. This means the
211/// performance is excellent, even with millions of `Signal`s running simultaneously.
212///
213/// Just like [`FutureExt`](https://docs.rs/futures/^0.3.15/futures/future/trait.FutureExt.html) and
214/// [`StreamExt`](https://docs.rs/futures/0.3.15/futures/stream/trait.StreamExt.html),
215/// the [`SignalExt`](../signal/trait.SignalExt.html) trait has many useful
216/// methods, and most of them return a `Signal` so they can be chained:
217///
218/// ```rust
219/// # use std::future::Future;
220/// # use futures_signals::signal::Mutable;
221/// # use futures_signals::signal::SignalExt;
222/// # fn do_some_async_calculation(value: u32) -> impl Future<Output = ()> { async {} }
223/// # fn main() {
224/// # let my_state = Mutable::new(3);
225/// #
226/// let output = my_state.signal()
227///     .map(|value| value + 5)
228///     .map_future(|value| do_some_async_calculation(value))
229///     .dedupe();
230/// # }
231/// ```
232///
233/// Let's say that the current value of `my_state` is `10`.
234///
235/// When `output` is spawned it will call the `|value| value + 5` closure with
236/// the current value of `my_value` (the closure returns `10 + 5`, which is `15`).
237///
238/// Then it calls `do_some_async_calculation(15)` which returns a `Future`.
239/// When that `Future` finishes, `dedupe` checks if the return value is
240/// different from the previous value (using `==`), and if so then `output`
241/// notifies with the new value.
242///
243/// It automatically repeats this process whenever `my_state` changes, ensuring
244/// that `output` is always kept in sync with `my_state`.
245///
246/// It is also possible to use [`map_ref`](../macro.map_ref.html) which is similar
247/// to [`map`](../signal/trait.SignalExt.html#method.map) except it allows you
248/// to use multiple input `Signal`s:
249///
250/// ```rust
251/// # use futures_signals::signal::Mutable;
252/// # fn main() {
253/// # let foo = Mutable::new(1);
254/// # let bar = Mutable::new(2);
255/// # let qux = Mutable::new(3);
256/// #
257/// use futures_signals::map_ref;
258///
259/// let output = map_ref! {
260///     let foo = foo.signal(),
261///     let bar = bar.signal(),
262///     let qux = qux.signal() =>
263///     *foo + *bar + *qux
264/// };
265/// # }
266/// ```
267///
268/// In this case `map_ref` is depending on three `Signal`s: `foo`, `bar`, and `qux`.
269///
270/// Whenever any of those `Signal`s changes, it will rerun the `*foo + *bar + *qux`
271/// code.
272///
273/// This means that `output` will always be equal to the sum of `foo`, `bar`, and `qux`.
274///
275/// ## Signals are lossy
276///
277/// It is important to understand that `for_each`, `to_stream`, and *all*
278/// other `SignalExt` methods are *lossy*: they might skip changes.
279///
280/// That is because they only care about the *most recent value*. So if the
281/// value changes multiple times in a short period of time it will only detect
282/// the most recent change.
283///
284/// Here is an example:
285///
286/// ```rust
287/// # use futures_signals::signal::Mutable;
288/// # let my_state = Mutable::new(10);
289/// #
290/// my_state.set(2);
291/// my_state.set(3);
292/// ```
293///
294/// In this case it will only detect the `3` change. The `2` change is
295/// completely ignored, like as if it never happened.
296///
297/// This is an intentional design choice: it is necessary for correctness and
298/// performance.
299///
300/// So whenever you are using a `Signal`, you must ***not*** rely on it being
301/// updated for intermediate values.
302///
303/// That might sound like a problem, but it's actually not a problem at all:
304/// `Signal`s are guaranteed to always be updated with the most recent value,
305/// so it's *only* intermediate values which aren't guaranteed.
306///
307/// This is similar to `RwLock`, which also does not give you access to past
308/// values (only the current value). So as long as your program only cares about
309/// the most recent value, then `Signal`s will work perfectly.
310///
311/// If you really *do* need all intermediate values (not just the most recent),
312/// then using a [`Stream`](https://docs.rs/futures/^0.3.15/futures/stream/trait.Stream.html)
313/// (such as [`futures::channel::mpsc::unbounded`](https://docs.rs/futures/^0.3.15/futures/channel/mpsc/fn.unbounded.html))
314/// would be a great choice. In that case you will pay a small performance
315/// penalty, because it has to hold the values in a queue.
316///
317/// And of course you can freely mix `Future`s, `Stream`s, and `Signal`s in
318/// your program, using each one where it is appropriate.
319///
320/// ## `MutableVec`
321///
322/// In addition to `Mutable` and `Signal`, there is also [`MutableVec`](../signal_vec/struct.MutableVec.html),
323/// [`SignalVec`](../signal_vec/trait.SignalVec.html), and [`SignalVecExt`](../signal_vec/trait.SignalVecExt.html).
324///
325/// As its name suggests, `MutableVec<A>` is very similar to `Mutable<Vec<A>>`,
326/// except it's *dramatically* more efficient: rather than being notified with
327/// the new `Vec`, instead you are notified with the *difference* between the
328/// old `Vec` and the new `Vec`.
329///
330/// Here is an example:
331///
332/// ```rust
333/// use futures_signals::signal_vec::MutableVec;
334///
335/// let my_vec: MutableVec<u32> = MutableVec::new();
336/// ```
337///
338/// The above creates a new empty `MutableVec`.
339///
340/// You can then use [`lock_mut`](../signal_vec/struct.MutableVec.html#method.lock_mut),
341/// which returns a lock. As its name implies, while you are holding the lock
342/// you have exclusive mutable access to the `MutableVec`.
343///
344/// The lock contains many of the `Vec` methods:
345///
346/// ```rust
347/// # use futures_signals::signal_vec::MutableVec;
348/// # let my_vec: MutableVec<u32> = MutableVec::new();
349/// #
350/// let mut lock = my_vec.lock_mut();
351/// lock.push(1);
352/// lock.insert(0, 2);
353/// lock.remove(0);
354/// lock.pop().unwrap();
355/// // And a lot more!
356/// ```
357///
358/// The insertion methods require `Copy`, but there are also `_cloned` variants
359/// which require `Clone` instead:
360///
361/// ```rust
362/// # use std::sync::Arc;
363/// # use futures_signals::signal_vec::MutableVec;
364/// # let my_vec: MutableVec<u32> = MutableVec::new();
365/// # let mut lock = my_vec.lock_mut();
366/// #
367/// lock.push_cloned(1);
368/// lock.insert_cloned(0, 2);
369/// // etc.
370/// ```
371///
372/// This is needed because when you insert a new value, it has to send a copy to
373/// all of the `SignalVec`s which are listening to changes.
374///
375/// The lock also has a `Deref` implementation for `&[T]`, so you can use *all*
376/// of the immutable [`slice`](https://doc.rust-lang.org/std/primitive.slice.html)
377/// methods on it:
378///
379/// ```rust
380/// # use futures_signals::signal_vec::MutableVec;
381/// # let my_vec: MutableVec<u32> = MutableVec::new_with_values(vec![0]);
382/// # let lock = my_vec.lock_mut();
383/// #
384/// let _ = lock[0];
385/// let _ = lock.len();
386/// let _ = lock.last();
387/// let _ = lock.iter();
388/// // And a lot more!
389/// ```
390///
391/// Lastly, you can use the [`signal_vec()`](../signal_vec/struct.MutableVec.html#method.signal_vec)
392/// or [`signal_vec_cloned()`](../signal_vec/struct.MutableVec.html#method.signal_vec_cloned)
393/// methods to convert it into a `SignalVec`, and then you can use the
394/// [`for_each`](../signal_vec/trait.SignalVecExt.html#method.for_each) method
395/// to be efficiently notified when it changes:
396///
397/// ```rust
398/// # use futures_signals::signal_vec::MutableVec;
399/// # let my_vec: MutableVec<u32> = MutableVec::new();
400/// #
401/// use futures_signals::signal_vec::{SignalVecExt, VecDiff};
402///
403/// let future = my_vec.signal_vec().for_each(|change| {
404///     match change {
405///         VecDiff::Replace { values } => {
406///             // ...
407///         },
408///         VecDiff::InsertAt { index, value } => {
409///             // ...
410///         },
411///         VecDiff::UpdateAt { index, value } => {
412///             // ...
413///         },
414///         VecDiff::RemoveAt { index } => {
415///             // ...
416///         },
417///         VecDiff::Move { old_index, new_index } => {
418///             // ...
419///         },
420///         VecDiff::Push { value } => {
421///             // ...
422///         },
423///         VecDiff::Pop {} => {
424///             // ...
425///         },
426///         VecDiff::Clear {} => {
427///             // ...
428///         },
429///     }
430///
431///     async {}
432/// });
433/// ```
434///
435/// Just like `SignalExt::for_each`, the `SignalVecExt::for_each` method returns
436/// a `Future`.
437///
438/// When that `Future` is spawned:
439///
440/// 1. If the `SignalVec` already has values, it calls the closure with
441///    `VecDiff::Replace`, which contains the current values for the `SignalVec`.
442///
443/// 2. If the `SignalVec` doesn't have any values, it doesn't call the closure.
444///
445/// 3. Whenever the `SignalVec` changes, it calls the closure with the `VecDiff`
446///    for the change.
447///
448/// Unlike `SignalExt::for_each`, the `SignalVecExt::for_each` method calls the
449/// closure with a [`VecDiff`](../signal_vec/enum.VecDiff.html), which contains
450/// the difference between the new `Vec` and the old `Vec`.
451///
452/// As an example, if you call `lock.push(5)`, then the closure will be called with `VecDiff::Push { value: 5 }`
453///
454/// And if you call `lock.insert(3, 10)`, then the closure will be called with `VecDiff::InsertAt { index: 3, value: 10 }`
455///
456/// This allows you to very efficiently update based only on that specific change.
457///
458/// For example, if you are automatically saving the `MutableVec` to a database
459/// whenever it changes, you don't need to save the entire `MutableVec` when it
460/// changes, you only need to save the individual changes. This means that it will
461/// often be constant `O(1)` time, no matter how big the `MutableVec` is.
462///
463/// ## `SignalVecExt`
464///
465/// Just like `SignalExt`, [`SignalVecExt`](../signal_vec/trait.SignalVecExt.html)
466/// has a lot of useful methods, and most of them return a `SignalVec` so they
467/// can be chained:
468///
469/// ```rust
470/// # use futures_signals::signal_vec::MutableVec;
471/// # let my_vec: MutableVec<u32> = MutableVec::new();
472/// # use futures_signals::signal_vec::SignalVecExt;
473/// #
474/// let output = my_vec.signal_vec()
475///     .filter(|value| *value < 5)
476///     .map(|value| value + 10);
477/// ```
478///
479/// They are generally very efficient (e.g. `map` is constant time, no matter
480/// how big the `SignalVec` is, and `filter` is linear time).
481///
482/// ## SignalVec is lossless
483///
484/// Unlike `Signal`, it is guaranteed that the `SignalVec` will never skip a
485/// change. In addition, the changes will always be in the correct order.
486///
487/// This is because it is notifying with the difference between the old `Vec`
488/// and the new `Vec`, so it is very important that it is in the correct order,
489/// and that it doesn't skip anything!
490///
491/// That does mean that `MutableVec` needs to maintain a queue of changes, so
492/// this has a minor performance cost.
493///
494/// But because it's so efficient to update based upon the difference between
495/// the old and new `Vec`, it's still often faster to use `MutableVec<A>` rather
496/// than `Mutable<Vec<A>>`, even with the extra performance overhead.
497///
498/// In addition, even though `MutableVec` needs to maintain a queue, `SignalVec`
499/// does ***not***, so it's quite efficient.
500///
501/// If you call a `MutableVec` method which doesn't *actually* make any changes,
502/// then it will not notify at all:
503///
504/// ```rust
505/// # use futures_signals::signal_vec::MutableVec;
506/// # let my_vec: MutableVec<u32> = MutableVec::new();
507/// #
508/// my_vec.lock_mut().retain(|_| { true });
509/// ```
510///
511/// The [`MutableVec::retain`](../signal_vec/struct.MutableVecLockMut.html#method.retain)
512/// method is the same as [`Vec::retain`](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.retain),
513/// it calls the closure for each value in the `MutableVec`, and if the closure
514/// returns `false` it removes that value from the `MutableVec`.
515///
516/// But in the above example, it never returns `false`, so it never removes
517/// anything, so it doesn't notify.
518///
519/// Also, even though it's guaranteed to send a notification for each change,
520/// the notification might be different than what you expect.
521///
522/// For example, when calling the `retain` method, it will send out a
523/// notification for each change, so if `retain` removes 5 values it will send
524/// out 5 notifications.
525///
526/// But, contrary to what you might expect, the notifications are in the reverse
527/// order: it sends notifications for the right-most values first, and
528/// notifications for the left-most values last. In addition, it sends a mixture
529/// of `VecDiff::Pop` and `VecDiff::RemoveAt`.
530///
531/// Another example is that [`remove`](../signal_vec/struct.MutableVecLockMut.html#method.remove)
532/// might notify with either `VecDiff::RemoveAt` or `VecDiff::Pop` depending on
533/// whether it removed the last value or not.
534///
535/// The reason for this is performance, and you should ***not*** rely
536/// upon it: the behavior of exactly which notifications are sent is an
537/// implementation detail.
538///
539/// However, there is one thing you *can* rely on: if you apply the
540/// notifications in the same order they are received, it will exactly recreate
541/// the `SignalVec`:
542///
543/// ```rust
544/// # use futures_signals::signal_vec::MutableVec;
545/// # let my_vec: MutableVec<u32> = MutableVec::new();
546/// # use futures_signals::signal_vec::{SignalVecExt, VecDiff};
547/// #
548/// let mut copied_vec = vec![];
549///
550/// let future = my_vec.signal_vec().for_each(move |change| {
551///     match change {
552///         VecDiff::Replace { values } => {
553///             copied_vec = values;
554///         },
555///         VecDiff::InsertAt { index, value } => {
556///             copied_vec.insert(index, value);
557///         },
558///         VecDiff::UpdateAt { index, value } => {
559///             copied_vec[index] = value;
560///         },
561///         VecDiff::RemoveAt { index } => {
562///             copied_vec.remove(index);
563///         },
564///         VecDiff::Move { old_index, new_index } => {
565///             let value = copied_vec.remove(old_index);
566///             copied_vec.insert(new_index, value);
567///         },
568///         VecDiff::Push { value } => {
569///             copied_vec.push(value);
570///         },
571///         VecDiff::Pop {} => {
572///             copied_vec.pop().unwrap();
573///         },
574///         VecDiff::Clear {} => {
575///             copied_vec.clear();
576///         },
577///     }
578///
579///     async {}
580/// });
581/// ```
582///
583/// In the above example, `copied_vec` is guaranteed to have exactly the same
584/// values as `my_vec`, in the same order as `my_vec`.
585///
586/// But even though the *end result* is guaranteed to be the same, the order of
587/// the individual changes is an unspecified implementation detail.
588///
589/// ## `MutableBTreeMap`
590///
591/// Just like how `MutableVec` is a `Signal` version of `Vec`, there is also
592/// [`MutableBTreeMap`](../signal_map/struct.MutableBTreeMap.html) which is a
593/// `Signal` version of [`BTreeMap`](https://doc.rust-lang.org/std/collections/struct.BTreeMap.html):
594///
595/// ```rust
596/// use futures_signals::signal_map::MutableBTreeMap;
597///
598/// let map = MutableBTreeMap::new();
599///
600/// let mut lock = map.lock_mut();
601/// lock.insert("foo", 5);
602/// lock.insert("bar", 10);
603/// ```
604///
605/// Similar to `MutableVec`, it notifies with a [`MapDiff`](../signal_map/enum.MapDiff.html),
606/// and of course it supports [`SignalMap`](../signal_map/trait.SignalMap.html)
607/// and [`SignalMapExt`](../signal_map/trait.SignalMapExt.html) for efficient
608/// transformations and notifications:
609///
610/// ```rust
611/// # use futures_signals::signal_map::MutableBTreeMap;
612/// # let map: MutableBTreeMap<&str, u32> = MutableBTreeMap::new();
613/// #
614/// use futures_signals::signal_map::{SignalMapExt, MapDiff};
615///
616/// let output = map.signal_map().for_each(|change| {
617///     match change {
618///         MapDiff::Replace { entries } => {
619///             // ...
620///         },
621///         MapDiff::Insert { key, value } => {
622///             // ...
623///         },
624///         MapDiff::Update { key, value } => {
625///             // ...
626///         },
627///         MapDiff::Remove { key } => {
628///             // ...
629///         },
630///         MapDiff::Clear {} => {
631///             // ...
632///         },
633///     }
634///
635///     async {}
636/// });
637/// ```
638///
639/// ## End
640///
641/// And that's the end of the tutorial! We didn't cover every method, but we
642/// covered enough for you to get started.
643///
644/// You can look at the documentation for information on every method (there's a
645/// lot of useful stuff in there!).
646pub mod tutorial {}