After grabbing the file path of the executable and appending nvs
on it in inner_main()
, I try to convert it to a string in main()
:
use std::{env, io, path::PathBuf, process};
fn inner_main() -> io::Result<PathBuf> {
let exe = env::current_exe()?;
let dir = exe.parent().expect("Executable must be in some directory");
let dir = dir.join("nvs");
Ok(dir)
}
fn main() {
let path = inner_main() as String;
println!("The current directory is {:?}", path);
process::exit(0);
}
It results in an error:
error[E0605]: non-primitive cast: `std::result::Result<std::path::PathBuf, std::io::Error>` as `std::string::String`
--> src/main.rs:11:16
|
11 | let path = inner_main() as String;
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait
How would I go about converting this to a String
or &str
?