osdb/src/meta_commands.rs

31 lines
746 B
Rust
Raw Normal View History

pub enum MetaCommand {
Exit,
}
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<Self, Self::Err> {
match s.trim() {
".exit" => Ok(MetaCommand::Exit),
cmd => Err(MetaCommandParseError::Unrecognized {
cmd: cmd.to_string(),
}),
}
}
}