From 8d039e3de33bee2bfd56cfca497f434e31d8de0b Mon Sep 17 00:00:00 2001 From: Ahurac Date: Thu, 11 Apr 2024 02:41:47 +0200 Subject: [PATCH] command : ajout fonction `add` --- src/command.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/command.rs b/src/command.rs index bced27d..1634de3 100644 --- a/src/command.rs +++ b/src/command.rs @@ -24,7 +24,7 @@ pub trait Command { pub struct CommandSequence { command: Box, - next_command: Option>, + next_command: Option>, } impl CommandSequence { @@ -34,6 +34,14 @@ impl CommandSequence { next_command: None, } } + + pub fn add(&mut self, command: impl Command + 'static) { + if self.next_command.is_none() { + self.next_command = Some(Box::new(CommandSequence::new(command))); + } else { + self.next_command.as_mut().unwrap().add(command); + } + } } impl Command for CommandSequence {