pub struct BaseDirs { /* private fields */ }Expand description
The BaseDirs struct provides access to the XDG base directories.
Implementations§
Source§impl BaseDirs
impl BaseDirs
Sourcepub fn new() -> Result<Self, Error>
pub fn new() -> Result<Self, Error>
Creates a new BaseDirs struct without a prefix.
§Errors
Returns an error if the home directory could not be found.
Sourcepub fn with_prefix(prefix: impl Into<String>) -> Result<Self, Error>
pub fn with_prefix(prefix: impl Into<String>) -> Result<Self, Error>
Creates a new BaseDirs struct with a prefix. The prefix is appended to the XDG
directories. For example, if the prefix is myapp, the config directory will be
~/.config/myapp.
§Errors
Returns an error if the home directory could not be found.
Sourcepub fn home(&self) -> &Path
pub fn home(&self) -> &Path
Returns the home directory determined by std::env::home_dir().
Sourcepub fn config_home(&self) -> &Path
pub fn config_home(&self) -> &Path
Returns the config directory specified by the XDG_CONFIG_HOME environment variable.
If the environment variable is not set, the default is home() + /.config.
§Without a prefix
For example:
On Linux: /home/<user>/.config
On Windows: C:\Users\<user>\.config
On macOS: /Users/<user>/.config
§With a prefix
For example:
On Linux: /home/<user>/.config/<prefix>
On Windows: C:\Users\<user>\.config\<prefix>
On macOS: /Users/<user>/.config/<prefix>
This function does not create the directory, nor does it check if the directory exists. Use crate::BaseDirsEx::create() to create the directory.
Sourcepub fn cache_home(&self) -> &Path
pub fn cache_home(&self) -> &Path
Returns the cache directory specified by the XDG_CACHE_HOME environment variable.
See config_home() for more information.
Sourcepub fn data_home(&self) -> &Path
pub fn data_home(&self) -> &Path
Returns the data directory specified by the XDG_DATA_HOME environment variable.
See config_home() for more information.
Sourcepub fn state_home(&self) -> &Path
pub fn state_home(&self) -> &Path
Returns the state directory specified by the XDG_STATE_HOME environment variable.
See config_home() for more information.
Sourcepub fn runtime_dir(&self) -> Option<&Path>
pub fn runtime_dir(&self) -> Option<&Path>
Returns the runtime directory specified by the XDG_RUNTIME_DIR environment variable.
If the environment variable is not set, this function returns None.