use futures::future::{BoxFuture, Future, FutureExt}; pub struct Command { futures: Vec>, } impl Command { pub fn none() -> Self { Self { futures: Vec::new(), } } pub fn attempt( future: impl Future + 'static + Send, f: impl Fn(T) -> A + 'static + Send, ) -> Command { Command { futures: vec![future.map(f).boxed()], } } pub fn batch(commands: impl Iterator>) -> Self { Self { futures: commands.flat_map(|command| command.futures).collect(), } } pub fn futures(self) -> Vec> { self.futures } } impl From for Command where A: Future + 'static + Send, { fn from(future: A) -> Self { Self { futures: vec![future.boxed()], } } } impl std::fmt::Debug for Command { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("Command").finish() } }