Reputation: 3135
static CONFIG_FILE: &str = "/.config/myapp/config.toml";
but I want to build an os agnostic path:
$HOME/.config/myapp/config.toml
Tried variations of:
static CONFIG_FILE: &str = dirs::home_dir().unwrap().join(".config").join("myapp").join("config.toml").to_str().unwrap();
but I get:
|
28 | static CONFIG_FILE: &str = dirs::home_dir().unwrap().join(".config").join("myapp").join("config.toml").to_str().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `~const Deref` is not implemented for `PathBuf`
The following seems to compile however the end part of the path is not platform agnostic.
/// Application configuration filename
static HOME: Lazy<String> = Lazy::new(|| { env::var("HOME").unwrap() } );
static CONFIG_FILE: Lazy<PathBuf> = Lazy::new(||{Path::new(&HOME.as_str()).join(".config/assimilate/config.toml")});
Upvotes: 3
Views: 379
Reputation: 6109
Try this:
static CONFIG_FILE: Lazy<PathBuf> = Lazy::new(||{dirs::home_dir().unwrap().join(".config").join("myapp").join("config.toml")});
Upvotes: 2