pub enum MetaCommand { Exit, } pub struct MetaCommandExecuteResult { pub should_exit: bool, } impl MetaCommand { pub fn execute(&self) -> MetaCommandExecuteResult { match self { MetaCommand::Exit => MetaCommandExecuteResult { should_exit: true }, } } } pub enum MetaCommandParseError { Unrecognized { cmd: String }, } impl std::fmt::Display for MetaCommandParseError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { MetaCommandParseError::Unrecognized { cmd } => { write!(f, "unrecognized meta-command {cmd:?}") } } } } impl std::str::FromStr for MetaCommand { type Err = MetaCommandParseError; fn from_str(s: &str) -> Result { match s.trim() { ".exit" => Ok(MetaCommand::Exit), cmd => Err(MetaCommandParseError::Unrecognized { cmd: cmd.to_string(), }), } } }