January 2018
Beginner to intermediate
454 pages
10h 8m
English
First, let's add a new entry into the Command enum (I won't do this every time, but the steps will remain the same):
enum Command {
Auth,
Syst,
Unknown(String),
}
Then, let's update the as_ref implementation:
impl AsRef<str> for Command {
fn as_ref(&self) -> &str {
match *self {
Command::Auth => "AUTH",
Command::Syst => "SYST",
Command::Unknown(_) => "UNKN",
}
}
}
Finally, let's update the Command::new method:
impl Command {
pub fn new(input: Vec<u8>) -> io::Result<Self> {
let mut iter = input.split(|&byte| byte == b' ');
let mut command = iter.next().expect("command in input").to_vec(); to_uppercase(&mut command); let data = iter.next(); let command = match command.as_slice() { b"AUTH" => Command::Auth, b"SYST" ...Read now
Unlock full access