I have a Rust application which works as a shell. I want to get the working directory the user is in using as little dependencies as possible.
I tried using
let path = env::current_dir();
print!("{} > ",path.display());
But it gives me the following error: method not found in `Result<PathBuf, std::io::Error>'
I tried running this in the rust playground and it worked alright, so I was wondering if any of you could help me with this
You can use std::env::current_dir
to get the current working directory.
You also need to use match
, std::result::Result::unwrap
, std::result::Result::expect
, ?
, or something else to handle the Err
variant of the Result
and access the value inside the Ok
variant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With