Feature gate: #![feature(fs_home_dirs)]
This is a tracking issue for std::fs::HomeDirs and related functionality.
Sister feature tracking issue: std::fs::MediaDirs
HomeDirs exposes common user directory paths useful for user application files. This supersedes the XDG APIs.
Public API
// mod std::fs
pub struct HomeDirs { /* ... */ }
impl HomeDirs {
fn empty() -> Self;
pub fn config_home(&self) -> Option<&Path>;
pub fn data_home(&self) -> Option<&Path>;
pub fn state_home(&self) -> Option<&Path>;
pub fn cache_home(&self) -> Option<&Path>;
pub fn set_config_home(&mut self, path: PathBuf) -> &mut Self;
pub fn set_data_home(&mut self, path: PathBuf) -> &mut Self;
pub fn set_state_home(&mut self, path: PathBuf) -> &mut Self;
pub fn set_cache_home(&mut self, path: PathBuf) -> &mut Self;
}
// mod std::os::darwin::fs
impl HomeDirsExt for HomeDirs { /* ... */ }
pub impl(self) trait HomeDirsExt {
fn sysdir() -> io::Result<Self>;
}
// mod std::os::unix::fs
impl HomeDirsExt for HomeDirs { /* ... */ }
pub impl(self) trait HomeDirsExt {
fn xdg() -> io::Result<Self>;
fn runtime_home(&self) -> Option<&Path>;
fn config_dirs(&self) -> Option<XdgDirs<'_>>;
fn data_dirs(&self) -> Option<XdgDirs<'_>>;
fn set_runtime_home(&mut self, path: PathBuf) -> &mut Self;
fn set_config_dirs(&mut self, paths: OsString) -> &mut Self;
fn set_data_dirs(&mut self, paths: OsString) -> &mut Self;
}
pub struct XdgDirs<'a> { /* ... */ }
impl Iterator for XdgDirs<'a> {
type Item = &'a Path;
/* ... */
}
// mod std::os::windows::fs
impl HomeDirsExt for HomeDirs { /* ... */ }
pub impl(self) trait HomeDirsExt {
fn appdata_env() -> io::Result<Self>;
fn known_folders() -> io::Result<Self>;
}
Steps / History
(Remember to update the S-tracking-* label when checking boxes.)
Unresolved Questions
Feature gate:
#![feature(fs_home_dirs)]This is a tracking issue for
std::fs::HomeDirsand related functionality.Sister feature tracking issue:
std::fs::MediaDirsHomeDirsexposes common user directory paths useful for user application files. This supersedes the XDG APIs.Public API
Steps / History
(Remember to update the
S-tracking-*label when checking boxes.)std::fs::UserDirsor similar libs-team#830std::fs::{Home|Media}Dirs#158936Unresolved Questions
fn take(&mut self) -> Selfmethod would be useful for builder-API style usage of theset_*methods. T-libs-api agreed we don't. I will defer to T-libs-api here, but want to log this note.HomeDirsExtprovidefn bin_home(&self) -> Option<&Path>? The XDG spec defines a bin home path to specifically$HOME/.local/binand$XDG_BIN_HOMEis a non-standard extension.HomeDirsExtprovide access to more of the PERUSERKNOWNFOLDERIDs?PATHis handled instead of mandating:as a separator. ShouldHomeDirs::xdg()be platform agnostic or limited to the Unix extension trait?XdgDirscan iterate&Pathor if it needs to iteratePathBuflikeenv::split_pathsdoes.std::fs::MediaDirs(feature(fs_media_dirs)) #162083.Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩