diff options
author | 2019-11-24 11:34:30 +0100 | |
---|---|---|
committer | 2019-11-24 11:34:30 +0100 | |
commit | 149fd2aa1fa86858c7c1dcec8fd844caa78cec94 (patch) | |
tree | a199cf8d2caaf6aa60e48e93d6dd0688969d43b0 /core/src/command.rs | |
parent | 9712b319bb7a32848001b96bd84977430f14b623 (diff) | |
parent | 47196c9007d12d3b3e0036ffabe3bf6d14ff4523 (diff) | |
download | iced-149fd2aa1fa86858c7c1dcec8fd844caa78cec94.tar.gz iced-149fd2aa1fa86858c7c1dcec8fd844caa78cec94.tar.bz2 iced-149fd2aa1fa86858c7c1dcec8fd844caa78cec94.zip |
Merge pull request #65 from hecrj/improvement/docs
Documentation
Diffstat (limited to 'core/src/command.rs')
-rw-r--r-- | core/src/command.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/core/src/command.rs b/core/src/command.rs index e1c865dd..14b48b5b 100644 --- a/core/src/command.rs +++ b/core/src/command.rs @@ -1,16 +1,30 @@ use futures::future::{BoxFuture, Future, FutureExt}; +/// A collection of async operations. +/// +/// You should be able to turn a future easily into a [`Command`], either by +/// using the `From` trait or [`Command::perform`]. +/// +/// [`Command`]: struct.Command.html pub struct Command<T> { futures: Vec<BoxFuture<'static, T>>, } impl<T> Command<T> { + /// Creates an empty [`Command`]. + /// + /// In other words, a [`Command`] that does nothing. + /// + /// [`Command`]: struct.Command.html pub fn none() -> Self { Self { futures: Vec::new(), } } + /// Creates a [`Command`] that performs the action of the given future. + /// + /// [`Command`]: struct.Command.html pub fn perform<A>( future: impl Future<Output = T> + 'static + Send, f: impl Fn(T) -> A + 'static + Send, @@ -20,12 +34,21 @@ impl<T> Command<T> { } } + /// Creates a [`Command`] that performs the actions of all the givens + /// futures. + /// + /// Once this command is run, all the futures will be exectued at once. + /// + /// [`Command`]: struct.Command.html pub fn batch(commands: impl Iterator<Item = Command<T>>) -> Self { Self { futures: commands.flat_map(|command| command.futures).collect(), } } + /// Converts a [`Command`] into its underlying list of futures. + /// + /// [`Command`]: struct.Command.html pub fn futures(self) -> Vec<BoxFuture<'static, T>> { self.futures } |