Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. use std::path::PathBuf;
  2. use std::env;
  3. use std::io;
  4.  
  5. fn inner_main() -> io::Result<PathBuf> {
  6. let exe = env::current_exe()?;
  7. let dir = exe.parent().expect("Executable must be in some directory");
  8. let dir = dir.join("nvs");
  9. Ok(dir)
  10. }
  11.  
  12. fn main() {
  13. // inner_main() returns a Result so you need to either handle the error or
  14. // do what I'm doing which will either return success or panic.
  15. let path = inner_main().expect("Couldn't get path");
  16.  
  17. // It's somewhat involved to turn a PathBuf into a String (and can fail)
  18. // but you can do it like this.
  19. let path_string = path.into_os_string().into_string().unwrap();
  20.  
  21. println!("Here is the string path: '{}'", path_string);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement