SHARE
TWEET

Untitled

a guest Jul 16th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top