refactor: pull things into own files, have a library

This commit is contained in:
Khaïs COLIN 2025-05-02 20:35:45 +02:00
parent 4848f2be2f
commit ee23572983
7 changed files with 176 additions and 166 deletions

30
src/meta_commands.rs Normal file
View file

@ -0,0 +1,30 @@
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(),
}),
}
}
}