Struct unidirs::ServiceDirs

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

Service directories are used for applications that run as a service (or often called daemon), usually run by a dedicated user account and controlled by the system rather than the user.

The directories are therefore rather global and close to the system instead of being located in the user’s home directory.

Unix (Linux, Mac OS and others)

On Unix systems the service folders are mostly standardized. Depending on how a service is run on Mac OS, the UserDirs might be correct as well, but for system-run services the correct folders are the same as on other Unix systems.

TypeLocation
Cache/var/cache/<app>
Config/etc/<app>
Data/var/lib/<app>

Windows

On Windows there are three standard service accounts: LocalService, NetworkService and LocalSystem. These present different capabilities and a network service provides a middle ground with minimal capabilities plus networking access.

The API might be extended to pick the type of service account in the future.

TypeLocation
CacheC:\Windows\ServiceProfiles\NetworkService\AppData\<org>\<app>\Local\cache
ConfigC:\Windows\ServiceProfiles\NetworkService\AppData\<org>\<app>\Roaming\config
DataC:\Windows\ServiceProfiles\NetworkService\AppData\<org>\<app>\Roaming\data

Implementations§

source§

impl ServiceDirs

source

pub fn new(organization: impl AsRef<str>, application: impl AsRef<str>) -> Self

Create a new instance with the given organization and application name. The organization name is only used on Windows systems.

Examples
use unidirs::{Directories, ServiceDirs};

let dirs = ServiceDirs::new("example", "app");

println!("data_dir = {}", dirs.data_dir());
// On Unix:    /var/lib/app
// On Windows: C:\Windows\ServiceProfiles\NetworkService\AppData\example\app\data

Trait Implementations§

source§

impl Clone for ServiceDirs

source§

fn clone(&self) -> ServiceDirs

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 ServiceDirs

source§

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

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

impl Directories for ServiceDirs

source§

fn cache_dir(&self) -> &Utf8Path

The cache directory is a location where an application can save any temporary data. The contents can potentially be deleted by the system at any time. Therefore, the application must be able to work without these files or be able to re-create them.
source§

fn config_dir(&self) -> &Utf8Path

The config directory is where an application’s settings are stored. These are usually created by the user and loaded once at startup of the application.
source§

fn data_dir(&self) -> &Utf8Path

The data directory hold an application’s state data, like a database. The folder is expected to persist during the normal runtime of the OS.
source§

impl Hash for ServiceDirs

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 ServiceDirs

source§

fn cmp(&self, other: &ServiceDirs) -> 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<ServiceDirs> for ServiceDirs

source§

fn eq(&self, other: &ServiceDirs) -> 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<ServiceDirs> for ServiceDirs

source§

fn partial_cmp(&self, other: &ServiceDirs) -> 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 ServiceDirs

source§

impl StructuralEq for ServiceDirs

source§

impl StructuralPartialEq for ServiceDirs

Auto Trait Implementations§

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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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.
const: unstable · 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.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.