January 2018
Beginner to intermediate
454 pages
10h 8m
English
First of all, we'll need a new attribute for our Client structure to specify what the current directory is:
use std::path::PathBuf; struct Client { cwd: PathBuf, writer: Writer, }
The cwd attribute stands for current working directory. We also need to update the Client constructor accordingly:
impl Client { fn new(writer: Writer) -> Client { Client { cwd: PathBuf::from("/"), writer, } } }
Now, we can add the handler for the PWD command:
#[async] fn handle_cmd(mut self, cmd: Command) -> Result<Self> { println!("Received command: {:?}", cmd); match cmd { Command::Pwd => { let msg = format!("{}", self.cwd.to_str().unwrap_or("")); if !msg.is_empty() { let message = format!("\"/{}\" ", msg); self = await!(self
Read now
Unlock full access