Trait HomeDirsExt
pub trait HomeDirsExt: Sized
XDG-specific extensions to fs::HomeDirs.
The XDG conventions are defined by the Freedesktop.org project in the XDG Base Directory Specification. These conventions have been largely adopted by Linux distributions.
The XDG conventions are written to be usable on any Unix-like filesystem,
thus this extension being provided in os::unix rather than os::linux.
However, while some tooling does use XDG conventions on macOS, note that
macOS has its own separate conventions for user directories. Consider
carefully what conventions your users will expect your application to
follow along with any legacy path compatibility you might need to support.
Required Methods
fn xdg() -> Result<Self>Load the user directory paths according to the XDG Base Directory Specification.
Each base directory path is set to the value of its corresponding
XDG_*environment variable (if it is set and non-empty), else to the default value defined by the specification.Field Environment Variable Default Value cache_homeXDG_CACHE_HOME$HOME/.cacheconfig_homeXDG_CONFIG_HOME$HOME/.configdata_homeXDG_DATA_HOME$HOME/.local/sharestate_homeXDG_STATE_HOME$HOME/.local/stateruntime_homeXDG_RUNTIME_DIR(see method docs) config_dirsXDG_CONFIG_DIRS/etc/xdgdata_dirsXDG_DATA_DIRS/usr/local/share/,/usr/share/Note that
$HOMEhere meansenv::home_dir, which uses$HOMEif set and non-empty, but falls back to the system password database if it isn't set.All paths are required to be absolute. If a relative path is configured by the environment, it is ignored and the default value is used instead.
config_dirsanddata_dirsare a list of delimited paths using theenv::split_pathsdelimiter. If some but not all paths in the list are relative, those relative paths are ignored and the remaining absolute paths are used. If there are no valid absolute paths, the default value is used instead.Errors
Errors if the user's home directory cannot be determined.
fn runtime_home(&self) -> Option<&Path>A base directory relative to which user-specific runtime files (such as sockets, named pipes, etc) should be stored.
Files in this directory may be subjected to periodic clean-up. Larger files should not be placed here, since it might reside in runtime memory and cannot necessarily be swapped out to disk.
This path does not have a default if not set. If it isn't set, applications should fall back to a replacement directory with similar capabilities and print a warning message.
fn config_dirs(&self) -> Option<XdgDirs<'_>>A preference-ordered list of base directories to search for config files in addition to
config_home.The order of directories denotes their importance; the first directory is the most important. Information defined relative to the more important base directory takes precedent.
config_homeis not necessarily present in this list, and is considered more important than any base directory in this list.fn data_dirs(&self) -> Option<XdgDirs<'_>>A preference-ordered list of base directories to search for data files in addition to
data_home.The order of directories denotes their importance; the first directory is the most important. Information defined relative to the more important base directory takes precedent.
data_homeis not necessarily present in this list, and is considered more important than any base directory in this list.fn set_runtime_home(&mut self, path: PathBuf) -> &mut SelfSet the path for [Self::runtime_home].
Panics
Panics if the provided path is not absolute.
fn set_config_dirs(&mut self, paths: OsString) -> &mut SelfSet the paths for [Self::config_dirs].
Takes one or more paths joined appropriately for the
PATHenvironment variable, as byenv::join_paths.Panics
Panics if any of the provided paths are not absolute.
fn set_data_dirs(&mut self, paths: OsString) -> &mut SelfSet the paths for [Self::data_dirs].
Takes one or more paths joined appropriately for the
PATHenvironment variable, as byenv::join_paths.Panics
Panics if any of the provided paths are not absolute.
Implementors
impl HomeDirsExt for HomeDirs