UserDirs

Struct 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::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§

Source§

impl UserDirs

Source

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 time new() was invoked, or
  • None, 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

Source

pub fn home_dir(&self) -> &Path

Returns the path to the user’s home directory.

PlatformValueExample
Linux$HOME/home/alice
macOS$HOME/Users/Alice
Windows{FOLDERID_Profile}C:\Users\Alice
Source

pub fn audio_dir(&self) -> Option<&Path>

Returns the path to the user’s audio directory.

PlatformValueExample
LinuxXDG_MUSIC_DIR/home/alice/Music
macOS$HOME/Music/Users/Alice/Music
Windows{FOLDERID_Music}C:\Users\Alice\Music
Source

pub fn desktop_dir(&self) -> Option<&Path>

Returns the path to the user’s desktop directory.

PlatformValueExample
LinuxXDG_DESKTOP_DIR/home/alice/Desktop
macOS$HOME/Desktop/Users/Alice/Desktop
Windows{FOLDERID_Desktop}C:\Users\Alice\Desktop
Source

pub fn document_dir(&self) -> Option<&Path>

Returns the path to the user’s document directory.

PlatformValueExample
LinuxXDG_DOCUMENTS_DIR/home/alice/Documents
macOS$HOME/Documents/Users/Alice/Documents
Windows{FOLDERID_Documents}C:\Users\Alice\Documents
Source

pub fn download_dir(&self) -> Option<&Path>

Returns the path to the user’s download directory.

PlatformValueExample
LinuxXDG_DOWNLOAD_DIR/home/alice/Downloads
macOS$HOME/Downloads/Users/Alice/Downloads
Windows{FOLDERID_Downloads}C:\Users\Alice\Downloads
Source

pub fn font_dir(&self) -> Option<&Path>

Returns the path to the user’s font directory.

PlatformValueExample
Linux$XDG_DATA_HOME/fonts or $HOME/.local/share/fonts/home/alice/.local/share/fonts
macOS$HOME/Library/Fonts/Users/Alice/Library/Fonts
Windows
Source

pub fn picture_dir(&self) -> Option<&Path>

Returns the path to the user’s picture directory.

PlatformValueExample
LinuxXDG_PICTURES_DIR/home/alice/Pictures
macOS$HOME/Pictures/Users/Alice/Pictures
Windows{FOLDERID_Pictures}C:\Users\Alice\Pictures
Source

pub fn public_dir(&self) -> Option<&Path>

Returns the path to the user’s public directory.

PlatformValueExample
LinuxXDG_PUBLICSHARE_DIR/home/alice/Public
macOS$HOME/Public/Users/Alice/Public
Windows{FOLDERID_Public}C:\Users\Public
Source

pub fn template_dir(&self) -> Option<&Path>

Returns the path to the user’s template directory.

PlatformValueExample
LinuxXDG_TEMPLATES_DIR/home/alice/Templates
macOS
Windows{FOLDERID_Templates}C:\Users\Alice\AppData\Roaming\Microsoft\Windows\Templates
Source

pub fn video_dir(&self) -> Option<&Path>

Returns the path to the user’s video directory.

PlatformValueExample
LinuxXDG_VIDEOS_DIR/home/alice/Videos
macOS$HOME/Movies/Users/Alice/Movies
Windows{FOLDERID_Videos}C:\Users\Alice\Videos

Trait Implementations§

Source§

impl Clone for UserDirs

Source§

fn clone(&self) -> UserDirs

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UserDirs

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 240 bytes