Struct directories::UserDirs [] [src]

pub struct UserDirs { /* fields omitted */ }

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;
let user_dirs = UserDirs::new();
user_dirs.audio_dir();
// Linux:   /home/alice/Music
// Windows: /Users/Alice/Music
// macOS:   C:\Users\Alice\Music

Methods

impl UserDirs
[src]

[src]

Creates a UserDirs struct which holds the paths to user-facing directories for audio, font, video, etc. data on the system. The returned struct is a snapshot of the state of the system at the time new() was invoked.

Panics

Panics if the home directory cannot be determined. See home_dir.

[src]

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

On Linux and macOS, this function uses std::env::home_dir to determine the home directory:

  • Use $HOME if it is set.
  • If $HOME is not set, the function getpwuid_r is used to determine the home directory of the current user.
  • If this also fails, creation of BaseDirs panics.

On Windows, this function retrieves the user profile folder using SHGetKnownFolderPath.

All the examples on this page mentioning $HOME use this behavior.

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

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

[src]

Returns the path to the user's video directory.

Platform Value Example
Linux XDG_VIDEOS_DIR /home/alice/Videos
macOS $HOME/Movies /Users/Alice/Movies
Windows {FOLDERID_Videos} C:\Users\Alice\Videos

Trait Implementations

impl Debug for UserDirs
[src]

[src]

Formats the value using the given formatter. Read more

impl Clone for UserDirs
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Send for UserDirs

impl Sync for UserDirs