Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Convert the PathBuf to String to compare

  • current_dir
  • clone
  • into_os_string
  • into_string
  • unwrap
fn main() {
    let cwd = std::env::current_dir().unwrap();
    println!("{:?}", cwd);
    //if cwd == "/home/gabor/work/slides/rust/examples/path/convert-pathbuf-to-string" {
    //    ^^ no implementation for `PathBuf == &str`

    if cwd.clone().into_os_string().into_string().unwrap()
        == "/home/gabor/work/slides/rust/examples/path/convert-pathbuf-to-string"
    {
        println!("at home");
    } else {
        println!("somewhere else");
    }
}