Struct directories_next::UserDirs
source · [−]pub struct UserDirs { /* private fields */ }
Expand description
UserDirs
provides paths of user-facing standard directories, following the conventions of the operating system the library is running on.
Examples
All examples on this page are computed with a user named Alice.
use directories_next::UserDirs;
if let Some(user_dirs) = UserDirs::new() {
user_dirs.audio_dir();
// Linux: /home/alice/Music
// Windows: C:\Users\Alice\Music
// macOS: /Users/Alice/Music
}
Implementations
sourceimpl UserDirs
impl UserDirs
sourcepub fn new() -> Option<UserDirs>
pub fn new() -> Option<UserDirs>
Creates a UserDirs
struct which holds the paths to user-facing directories for audio, font, video, etc. data on the system.
The returned value depends on the operating system and is either
Some
, containing a snapshot of the state of the system’s paths at the timenew()
was invoked, orNone
, if no valid home directory path could be retrieved from the operating system.
To determine whether a system provides a valid $HOME
path, please refer to BaseDirs::new
sourcepub fn home_dir(&self) -> &Path
pub fn home_dir(&self) -> &Path
Returns the path to the user’s home directory.
Platform | Value | Example |
---|---|---|
Linux | $HOME | /home/alice |
macOS | $HOME | /Users/Alice |
Windows | {FOLDERID_Profile} | C:\Users\Alice |
sourcepub fn audio_dir(&self) -> Option<&Path>
pub fn audio_dir(&self) -> Option<&Path>
Returns the path to the user’s audio directory.
Platform | Value | Example |
---|---|---|
Linux | XDG_MUSIC_DIR | /home/alice/Music |
macOS | $HOME /Music | /Users/Alice/Music |
Windows | {FOLDERID_Music} | C:\Users\Alice\Music |
sourcepub fn desktop_dir(&self) -> Option<&Path>
pub fn desktop_dir(&self) -> Option<&Path>
Returns the path to the user’s desktop directory.
Platform | Value | Example |
---|---|---|
Linux | XDG_DESKTOP_DIR | /home/alice/Desktop |
macOS | $HOME /Desktop | /Users/Alice/Desktop |
Windows | {FOLDERID_Desktop} | C:\Users\Alice\Desktop |
sourcepub fn document_dir(&self) -> Option<&Path>
pub fn document_dir(&self) -> Option<&Path>
Returns the path to the user’s document directory.
Platform | Value | Example |
---|---|---|
Linux | XDG_DOCUMENTS_DIR | /home/alice/Documents |
macOS | $HOME /Documents | /Users/Alice/Documents |
Windows | {FOLDERID_Documents} | C:\Users\Alice\Documents |
sourcepub fn download_dir(&self) -> Option<&Path>
pub fn download_dir(&self) -> Option<&Path>
Returns the path to the user’s download directory.
Platform | Value | Example |
---|---|---|
Linux | XDG_DOWNLOAD_DIR | /home/alice/Downloads |
macOS | $HOME /Downloads | /Users/Alice/Downloads |
Windows | {FOLDERID_Downloads} | C:\Users\Alice\Downloads |
sourcepub fn font_dir(&self) -> Option<&Path>
pub fn font_dir(&self) -> Option<&Path>
Returns the path to the user’s font directory.
Platform | Value | Example |
---|---|---|
Linux | $XDG_DATA_HOME /fonts or $HOME /.local/share/fonts | /home/alice/.local/share/fonts |
macOS | $HOME /Library/Fonts | /Users/Alice/Library/Fonts |
Windows | – | – |
sourcepub fn picture_dir(&self) -> Option<&Path>
pub fn picture_dir(&self) -> Option<&Path>
Returns the path to the user’s picture directory.
Platform | Value | Example |
---|---|---|
Linux | XDG_PICTURES_DIR | /home/alice/Pictures |
macOS | $HOME /Pictures | /Users/Alice/Pictures |
Windows | {FOLDERID_Pictures} | C:\Users\Alice\Pictures |
sourcepub fn public_dir(&self) -> Option<&Path>
pub fn public_dir(&self) -> Option<&Path>
Returns the path to the user’s public directory.
Platform | Value | Example |
---|---|---|
Linux | XDG_PUBLICSHARE_DIR | /home/alice/Public |
macOS | $HOME /Public | /Users/Alice/Public |
Windows | {FOLDERID_Public} | C:\Users\Public |
sourcepub fn template_dir(&self) -> Option<&Path>
pub fn template_dir(&self) -> Option<&Path>
Returns the path to the user’s template directory.
Platform | Value | Example |
---|---|---|
Linux | XDG_TEMPLATES_DIR | /home/alice/Templates |
macOS | – | – |
Windows | {FOLDERID_Templates} | C:\Users\Alice\AppData\Roaming\Microsoft\Windows\Templates |
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for UserDirs
impl Send for UserDirs
impl Sync for UserDirs
impl Unpin for UserDirs
impl UnwindSafe for UserDirs
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more