January 2018
Beginner to intermediate
454 pages
10h 8m
English
Let's add another case in our match expression in the handle_cmd() method:
#[async] fn handle_cmd(mut self, cmd: Command) -> Result<Self> { match cmd { Command::Cwd(directory) => self = await!(self.cwd(directory))?, // … } }
It simply calls the following method:
#[async] fn cwd(mut self, directory: PathBuf) -> Result<Self> { let path = self.cwd.join(&directory); let (new_self, res) = self.complete_path(path); self = new_self; if let Ok(dir) = res { let (new_self, res) = self.strip_prefix(dir); self = new_self; if let Ok(prefix) = res { self.cwd = prefix.to_path_buf(); self = await!(self.send(Answer::new(ResultCode::Ok, &format!("Directory changed to \" {}\"", directory.display()))))?; return Ok(self) } }