Struct etcetera::app_strategy::Unix

source ·
pub struct Unix { /* private fields */ }
Expand description

This strategy has no standard or official specification. It has arisen over time through hundreds of Unixy tools. Vim and Cargo are notable examples whose configuration/data/cache directory layouts are similar to those created by this strategy.

use etcetera::app_strategy::AppStrategy;
use etcetera::app_strategy::AppStrategyArgs;
use etcetera::app_strategy::Unix;
use std::path::Path;

let app_strategy = Unix::new(AppStrategyArgs {
    top_level_domain: "org".to_string(),
    author: "Acme Corp".to_string(),
    app_name: "Frobnicator Plus".to_string(),
}).unwrap();

let home_dir = etcetera::home_dir().unwrap();

assert_eq!(
    app_strategy.home_dir(),
    &home_dir
);
assert_eq!(
    app_strategy.config_dir().strip_prefix(&home_dir),
    Ok(Path::new(".frobnicator-plus/"))
);
assert_eq!(
    app_strategy.data_dir().strip_prefix(&home_dir),
    Ok(Path::new(".frobnicator-plus/data/"))
);
assert_eq!(
    app_strategy.cache_dir().strip_prefix(&home_dir),
    Ok(Path::new(".frobnicator-plus/cache/"))
);
assert_eq!(
    app_strategy.state_dir().unwrap().strip_prefix(&home_dir),
    Ok(Path::new(".frobnicator-plus/state/"))
);
assert_eq!(
    app_strategy.runtime_dir().unwrap().strip_prefix(&home_dir),
    Ok(Path::new(".frobnicator-plus/runtime/"))
);

Trait Implementations§

source§

impl AppStrategy for Unix

§

type CreationError = HomeDirError

The error type returned by new.
source§

fn new(args: AppStrategyArgs) -> Result<Self, Self::CreationError>

The constructor requires access to some basic information about your application.
source§

fn home_dir(&self) -> &Path

Gets the home directory of the current user.
source§

fn config_dir(&self) -> PathBuf

Gets the configuration directory for your application.
source§

fn data_dir(&self) -> PathBuf

Gets the data directory for your application.
source§

fn cache_dir(&self) -> PathBuf

Gets the cache directory for your application.
source§

fn state_dir(&self) -> Option<PathBuf>

Gets the state directory for your application. State directory may not to exist for all conventions.
source§

fn runtime_dir(&self) -> Option<PathBuf>

Gets the runtime directory for your application. Runtime directory may not to exist for all conventions.
source§

fn in_config_dir<P: AsRef<OsStr>>(&self, path: P) -> PathBuf

Constructs a path inside your application’s configuration directory to which a path of your choice has been appended.
source§

fn in_data_dir<P: AsRef<OsStr>>(&self, path: P) -> PathBuf

Constructs a path inside your application’s data directory to which a path of your choice has been appended.
source§

fn in_cache_dir<P: AsRef<OsStr>>(&self, path: P) -> PathBuf

Constructs a path inside your application’s cache directory to which a path of your choice has been appended.
source§

fn in_state_dir<P: AsRef<OsStr>>(&self, path: P) -> Option<PathBuf>

Constructs a path inside your application’s state directory to which a path of your choice has been appended.
source§

fn in_runtime_dir<P: AsRef<OsStr>>(&self, path: P) -> Option<PathBuf>

Constructs a path inside your application’s runtime directory to which a path of your choice has been appended.
source§

impl Clone for Unix

source§

fn clone(&self) -> Unix

Returns a copy 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 Unix

source§

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

Formats the value using the given formatter. Read more
source§

impl Hash for Unix

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Unix

source§

fn cmp(&self, other: &Unix) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<Unix> for Unix

source§

fn eq(&self, other: &Unix) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Unix> for Unix

source§

fn partial_cmp(&self, other: &Unix) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for Unix

source§

impl StructuralEq for Unix

source§

impl StructuralPartialEq for Unix

Auto Trait Implementations§

§

impl RefUnwindSafe for Unix

§

impl Send for Unix

§

impl Sync for Unix

§

impl Unpin for Unix

§

impl UnwindSafe for Unix

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.