BaseDirs

Struct BaseDirs 

Source
pub struct BaseDirs { /* private fields */ }
Expand description

The BaseDirs struct provides access to the XDG base directories.

Implementations§

Source§

impl BaseDirs

Source

pub fn new() -> Result<Self, Error>

Creates a new BaseDirs struct without a prefix.

§Errors

Returns an error if the home directory could not be found.

Source

pub fn with_prefix(prefix: impl Into<String>) -> Result<Self, Error>

Creates a new BaseDirs struct with a prefix. The prefix is appended to the XDG directories. For example, if the prefix is myapp, the config directory will be ~/.config/myapp.

§Errors

Returns an error if the home directory could not be found.

Source

pub fn home(&self) -> &Path

Returns the home directory determined by std::env::home_dir().

Source

pub fn config_home(&self) -> &Path

Returns the config directory specified by the XDG_CONFIG_HOME environment variable. If the environment variable is not set, the default is home() + /.config.

§Without a prefix

For example:
On Linux: /home/<user>/.config
On Windows: C:\Users\<user>\.config
On macOS: /Users/<user>/.config

§With a prefix

For example:
On Linux: /home/<user>/.config/<prefix>
On Windows: C:\Users\<user>\.config\<prefix>
On macOS: /Users/<user>/.config/<prefix>

This function does not create the directory, nor does it check if the directory exists. Use crate::BaseDirsEx::create() to create the directory.

Source

pub fn cache_home(&self) -> &Path

Returns the cache directory specified by the XDG_CACHE_HOME environment variable. See config_home() for more information.

Source

pub fn data_home(&self) -> &Path

Returns the data directory specified by the XDG_DATA_HOME environment variable. See config_home() for more information.

Source

pub fn state_home(&self) -> &Path

Returns the state directory specified by the XDG_STATE_HOME environment variable. See config_home() for more information.

Source

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

Returns the runtime directory specified by the XDG_RUNTIME_DIR environment variable. If the environment variable is not set, this function returns None.

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> 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, 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.