Skip to main content

AppPaths

Struct AppPaths 

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

Resolved OS-correct application directories (config and data).

Construct with AppPaths::new for production code, or AppPaths::for_testing in tests and headless CI environments. Use AppPaths::from_dirs when the application manages its own directory layout (e.g. portable mode).

Implementations§

Source§

impl AppPaths

Source

pub fn new( qualifier: &str, organization: &str, application: &str, ) -> Option<Self>

Resolve directories from the OS. The (qualifier, organization, application) triple feeds [etcetera::AppStrategyArgs] as (top_level_domain, author, app_name) — same fields, different names — and selects the platform-native strategy (XDG on Linux, %APPDATA%-based on Windows, ~/Library/Application Support on macOS).

Returns None when no usable home directory could be detected (a sandboxed or unconfigured environment). Callers who want to degrade gracefully should fall back to AppPaths::for_testing with an in-process directory.

Source

pub fn for_testing(root: &Path) -> Self

Construct an AppPaths rooted at an arbitrary directory. Used by tests so that no test ever touches the user’s real config tree. Both config_dir and data_dir resolve to root.

Source

pub fn from_dirs(config_dir: PathBuf, data_dir: PathBuf) -> Self

Construct from explicit config and data directories. Useful when an application wants to override one or both (e.g. portable mode).

Source

pub fn config_dir(&self) -> &Path

The platform-correct config directory (XDG_CONFIG_HOME, %APPDATA%, ~/Library/Preferences, etc.).

Source

pub fn data_dir(&self) -> &Path

The platform-correct data directory. Used for caches and per-window state — anything larger than a configuration file.

Source

pub fn config_file(&self, name: &str) -> PathBuf

Resolve a per-concern config file by name (without extension). name = "general" yields <config_dir>/general.toml.

Source

pub fn data_file(&self, name: &str) -> PathBuf

Resolve a per-concern data file by name (without extension).

Trait Implementations§

Source§

impl Clone for AppPaths

Source§

fn clone(&self) -> AppPaths

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for AppPaths

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.