[][src]Struct directories::ProjectDirs

pub struct ProjectDirs { /* fields omitted */ }

ProjectDirs computes the location of cache, config or data directories for a specific application, which are derived from the standard directories and the name of the project/organization.

Examples

All examples on this page are computed with a user named Alice, and a ProjectDirs struct created with ProjectDirs::from("com", "Foo Corp", "Bar App").

use directories::ProjectDirs;
if let Some(proj_dirs) = ProjectDirs::from("com", "Foo Corp",  "Bar App") {
    proj_dirs.config_dir();
    // Linux:   /home/alice/.config/barapp
    // Windows: C:\Users\Alice\AppData\Roaming\Foo Corp\Bar App
    // macOS:   /Users/Alice/Library/Preferences/com.Foo-Corp.Bar-App
}

Methods

impl ProjectDirs
[src]

Creates a ProjectDirs struct directly from a PathBuf value. The argument is used verbatim and is not adapted to operating system standards.

The use of ProjectDirs::from_path is strongly discouraged, as its results will not follow operating system standards on at least two of three platforms.

Use ProjectDirs::from instead.

Creates a ProjectDirs struct from values describing the project.

The returned value depends on the operating system and is either

  • Some, containing project directory paths based on 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

The use of ProjectDirs::from (instead of ProjectDirs::from_path) is strongly encouraged, as its results will follow operating system standards on Linux, macOS and Windows.

Parameters

  • qualifier – The reverse domain name notation of the application, excluding the organization or application name itself.
    An empty string can be passed if no qualifier should be used (only affects macOS).
    Example values: "com.example", "org", "uk.co", "io", ""
  • organization – The name of the organization that develops this application, or for which the application is developed.
    An empty string can be passed if no organization should be used (only affects macOS and Windows).
    Example values: "Foo Corp", "Alice and Bob Inc", ""
  • application – The name of the application itself.
    Example values: "Bar App", "ExampleProgram", "Unicorn-Programme"

Panics

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

Returns the project path fragment used to compute the project's cache/config/data directories. The value is derived from the ProjectDirs::from call and is platform-dependent.

Returns the path to the project's cache directory.

Platform Value Example
Linux $XDG_CACHE_HOME/_project_path_ or $HOME/.cache/_project_path_ /home/alice/.cache/barapp
macOS $HOME/Library/Caches/_project_path_ /Users/Alice/Library/Caches/com.Foo-Corp.Bar-App
Windows {FOLDERID_LocalAppData}`project_path`\cache C:\Users\Alice\AppData\Local\Foo Corp\Bar App\cache

Returns the path to the project's config directory.

Platform Value Example
Linux $XDG_CONFIG_HOME/_project_path_ or $HOME/.config/_project_path_ /home/alice/.config/barapp
macOS $HOME/Library/Preferences/_project_path_ /Users/Alice/Library/Preferences/com.Foo-Corp.Bar-App
Windows {FOLDERID_RoamingAppData}`project_path`\config C:\Users\Alice\AppData\Roaming\Foo Corp\Bar App\config

Returns the path to the project's data directory.

Platform Value Example
Linux $XDG_DATA_HOME/_project_path_ or $HOME/.local/share/_project_path_ /home/alice/.local/share/barapp
macOS $HOME/Library/Application Support/_project_path_ /Users/Alice/Library/Application Support/com.Foo-Corp.Bar-App
Windows {FOLDERID_RoamingAppData}`project_path`\data C:\Users\Alice\AppData\Roaming\Foo Corp\Bar App\data

Returns the path to the project's local data directory.

Platform Value Example
Linux $XDG_DATA_HOME/_project_path_ or $HOME/.local/share/_project_path_ /home/alice/.local/share/barapp
macOS $HOME/Library/Application Support/_project_path_ /Users/Alice/Library/Application Support/com.Foo-Corp.Bar-App
Windows {FOLDERID_LocalAppData}`project_path`\data C:\Users\Alice\AppData\Local\Foo Corp\Bar App\data

Returns the path to the project's runtime directory.

Platform Value Example
Linux $XDG_RUNTIME_DIR/_project_path_ /run/user/1001/barapp
macOS
Windows

Trait Implementations

impl Clone for ProjectDirs
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for ProjectDirs
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl Send for ProjectDirs

impl Sync for ProjectDirs

Blanket Implementations

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Immutably borrows from an owned value. Read more

impl<T> Any for T where
    T: 'static + ?Sized
[src]

🔬 This is a nightly-only experimental API. (get_type_id)

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Mutably borrows from an owned value. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.