use super::IntoCommand; #[derive(Default)] pub struct BatchCommand { commands: Vec, } impl BatchCommand { pub fn with(&mut self, cmd: impl IntoCommand) -> &mut Self { self.commands.push(cmd.into_command()); self } } impl IntoCommand for Vec { fn into_command(self) -> super::Command { BatchCommand::from(self).into_command() } } impl From> for BatchCommand { fn from(value: Vec) -> Self { BatchCommand { commands: value } } } impl IntoCommand for BatchCommand { fn into_command(self) -> super::Command { super::Command::new(|dispatch| { for command in self.commands { let msg = command.execute(dispatch.clone()); if let Some(msg) = msg { dispatch.send(msg); } } None }) } }