1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
use std::str::FromStr;
use ErrorKind;

/// Supported commands.
pub enum Command {
    /// A default command "s".
    S,
    /// An empty command, same as `Command::S`.
    Empty,
}

impl FromStr for Command {
    type Err = ErrorKind;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "" => Ok(Command::Empty),
            "s" => Ok(Command::S),
            cmd => Err(ErrorKind::UnknownCommand(cmd.into())),
        }
    }
}