pub trait MediaDirsExt: Sized {
// Required methods
fn xdg() -> Result<Self>;
fn templates(&self) -> Option<&Path>;
fn set_templates(&mut self, path: PathBuf) -> &mut Self;
}std.fs_media_dirs #162083)Expand description
XDG-specific extensions to fs::MediaDirs.
The XDG conventions are defined by the Freedesktop.org project through the xdg-user-dirs tool. This configuration is generally present on desktop Linux distributions, although adoption is less widespread than the base directory specification.
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§
Sourcefn xdg() -> Result<Self>
🔬This is a nightly-only experimental API. (fs_media_dirs #162083)
fn xdg() -> Result<Self>
fs_media_dirs #162083)Load the user directory paths according to the xdg-user-dirs tool.
This directly reads and parses the $XDG_CONFIG_HOME/user-dirs.dirs
file as defined and maintained by the xdg-user-dirs tool.
§Errors
Errors if the user’s home directory cannot be determined or if the
$XDG_CONFIG_HOME/user-dirs.dirs file cannot be read.
§Implementation-specific behavior
Only the format maintained by xdg-user-dirs-update is supported. Any
configuration that does not match the expected format will result in
loading an unspecified path or None for that directory. To be more
specific:
- Any line not in the format of
XDG_{NAME}_DIR={path}where{NAME}is one ofDESKTOP,DOWNLOAD,TEMPLATES,PUBLICSHARE,DOCUMENTS,MUSIC,PICTURES, orVIDEOSis ignored. {path}must be a"-quoted shell-escaped path.{path}may only start with/or$HOME/. A home-relative path is returned relative toenv::home_dir; shell expansion is not performed.- A directory set to just
$HOMEmarks it as removed, and results in aNonevalue for that path. - If shell expansion syntax other than a leading
$HOMEis present, the produced directory path is unspecified. This is invalid config according to the xdg-user-dirs tooling.
This behavior may change in the future. One example change that we
explicitly reserve the right to make is to load paths that we currently
ignore, such as path formats that are not canonically supported by
xdg-user-dirs but which may occur in manually-edited user-dirs.dirs.
Sourcefn templates(&self) -> Option<&Path>
🔬This is a nightly-only experimental API. (fs_media_dirs #162083)
fn templates(&self) -> Option<&Path>
fs_media_dirs #162083)The OS-privileged user “Templates” directory, often the Templates
folder in the user’s home directory.
As a media directory, this should typically be used as a default path for file selection dialogs, not for automatically accessed file paths.
Sourcefn set_templates(&mut self, path: PathBuf) -> &mut Self
🔬This is a nightly-only experimental API. (fs_media_dirs #162083)
fn set_templates(&mut self, path: PathBuf) -> &mut Self
fs_media_dirs #162083)Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".