SystemdDirs

Struct SystemdDirs 

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

A struct to snapshot the environment at the time of creation.

The SystemdDirs methods return Path objects as immutable references to the paths as available when Self::new was called. This differs from the standalone functions, which return PathBuf objects.

Implementations§

Source§

impl SystemdDirs

Source

pub fn new() -> Self

Returns a new SystemdDirs struct with a snapshot of the current environment.

§Examples
use systemd_directories::SystemdDirs;
let dirs = SystemdDirs::new();
Examples found in repository?
examples/struct.rs (line 5)
3fn main() {
4    // NOTE: These will possibly be empty if not running under systemd
5    let dirs = SystemdDirs::new();
6    println!("runtime dir: {:?}", dirs.runtime_dir());
7    println!("state dir: {:?}", dirs.state_dir());
8    println!("cache dir: {:?}", dirs.cache_dir());
9    println!("log dir: {:?}", dirs.logs_dir());
10    println!("config dir: {:?}", dirs.config_dir());
11}
More examples
Hide additional examples
examples/struct_multiple.rs (line 5)
3fn main() {
4    // NOTE: These will possibly be empty if not running under systemd
5    let dirs = SystemdDirs::new();
6    println!("runtime dir: {:?}", dirs.runtime_dirs());
7    println!("state dir: {:?}", dirs.state_dirs());
8    println!("cache dir: {:?}", dirs.cache_dirs());
9    println!("log dir: {:?}", dirs.logs_dirs());
10    println!("config dir: {:?}", dirs.config_dirs());
11}
Source

pub fn runtime_dirs(&self) -> Vec<&Path>

Returns all runtime directories as defined by RuntimeDirectory in the unit file.

If the environment variable RUNTIME_DIRECTORY was not set when SystemdDirs was created, it returns an empty vector. If it was set, it returns all paths in the colon-separated list. To get just the first path, use Self::runtime_dir.

§Examples
let dirs = systemd_directories::SystemdDirs::new();
let runtime_dirs = dirs.runtime_dirs();
Examples found in repository?
examples/struct_multiple.rs (line 6)
3fn main() {
4    // NOTE: These will possibly be empty if not running under systemd
5    let dirs = SystemdDirs::new();
6    println!("runtime dir: {:?}", dirs.runtime_dirs());
7    println!("state dir: {:?}", dirs.state_dirs());
8    println!("cache dir: {:?}", dirs.cache_dirs());
9    println!("log dir: {:?}", dirs.logs_dirs());
10    println!("config dir: {:?}", dirs.config_dirs());
11}
Source

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

Returns the first runtime directory as defined by RuntimeDirectory in the unit file.

If the environment variable RUNTIME_DIRECTORY was not set when SystemdDirs was created, it returns None. If it was set, it returns the first path in the colon-separated list. To get all paths, use Self::runtime_dirs.

§Examples
let dirs = systemd_directories::SystemdDirs::new();
let runtime_dir = dirs.runtime_dir();
Examples found in repository?
examples/struct.rs (line 6)
3fn main() {
4    // NOTE: These will possibly be empty if not running under systemd
5    let dirs = SystemdDirs::new();
6    println!("runtime dir: {:?}", dirs.runtime_dir());
7    println!("state dir: {:?}", dirs.state_dir());
8    println!("cache dir: {:?}", dirs.cache_dir());
9    println!("log dir: {:?}", dirs.logs_dir());
10    println!("config dir: {:?}", dirs.config_dir());
11}
Source

pub fn state_dirs(&self) -> Vec<&Path>

Returns all state directories as defined by StateDirectory in the unit file.

If the environment variable STATE_DIRECTORY was not set when SystemdDirs was created, it returns an empty vector. If it was set, it returns all paths in the colon-separated list. To get just the first path, use Self::state_dir.

§Examples
let dirs = systemd_directories::SystemdDirs::new();
let state_dirs = dirs.state_dirs();
Examples found in repository?
examples/struct_multiple.rs (line 7)
3fn main() {
4    // NOTE: These will possibly be empty if not running under systemd
5    let dirs = SystemdDirs::new();
6    println!("runtime dir: {:?}", dirs.runtime_dirs());
7    println!("state dir: {:?}", dirs.state_dirs());
8    println!("cache dir: {:?}", dirs.cache_dirs());
9    println!("log dir: {:?}", dirs.logs_dirs());
10    println!("config dir: {:?}", dirs.config_dirs());
11}
Source

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

Returns the first state directory as defined by StateDirectory in the unit file.

If the environment variable STATE_DIRECTORY was not set when SystemdDirs was created, it returns None. If it was set, it returns the first path in the colon-separated list. To get all paths, use Self::state_dirs.

§Examples
let dirs = systemd_directories::SystemdDirs::new();
let state_dir = dirs.state_dir();
Examples found in repository?
examples/struct.rs (line 7)
3fn main() {
4    // NOTE: These will possibly be empty if not running under systemd
5    let dirs = SystemdDirs::new();
6    println!("runtime dir: {:?}", dirs.runtime_dir());
7    println!("state dir: {:?}", dirs.state_dir());
8    println!("cache dir: {:?}", dirs.cache_dir());
9    println!("log dir: {:?}", dirs.logs_dir());
10    println!("config dir: {:?}", dirs.config_dir());
11}
Source

pub fn cache_dirs(&self) -> Vec<&Path>

Returns all cache directories as defined by CacheDirectory in the unit file.

If the environment variable CACHE_DIRECTORY was not set when SystemdDirs was created, it returns an empty vector. If it was set, it returns all paths in the colon-separated list. To get just the first path, use Self::cache_dir.

§Examples
let dirs = systemd_directories::SystemdDirs::new();
let cache_dirs = dirs.cache_dirs();
Examples found in repository?
examples/struct_multiple.rs (line 8)
3fn main() {
4    // NOTE: These will possibly be empty if not running under systemd
5    let dirs = SystemdDirs::new();
6    println!("runtime dir: {:?}", dirs.runtime_dirs());
7    println!("state dir: {:?}", dirs.state_dirs());
8    println!("cache dir: {:?}", dirs.cache_dirs());
9    println!("log dir: {:?}", dirs.logs_dirs());
10    println!("config dir: {:?}", dirs.config_dirs());
11}
Source

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

Returns the first cache directory as defined by CacheDirectory in the unit file.

If the environment variable CACHE_DIRECTORY was not set when SystemdDirs was created, it returns None. If it was set, it returns the first path in the colon-separated list. To get all paths, use Self::cache_dirs.

§Examples
let dirs = systemd_directories::SystemdDirs::new();
let cache_dir = dirs.cache_dir();
Examples found in repository?
examples/struct.rs (line 8)
3fn main() {
4    // NOTE: These will possibly be empty if not running under systemd
5    let dirs = SystemdDirs::new();
6    println!("runtime dir: {:?}", dirs.runtime_dir());
7    println!("state dir: {:?}", dirs.state_dir());
8    println!("cache dir: {:?}", dirs.cache_dir());
9    println!("log dir: {:?}", dirs.logs_dir());
10    println!("config dir: {:?}", dirs.config_dir());
11}
Source

pub fn logs_dirs(&self) -> Vec<&Path>

Returns all logs directories as defined by LogsDirectory in the unit file.

If the environment variable LOGS_DIRECTORY was not set when SystemdDirs was created, it returns an empty vector. If it was set, it returns all paths in the colon-separated list. To get just the first path, use Self::logs_dir.

§Examples
let dirs = systemd_directories::SystemdDirs::new();
let logs_dirs = dirs.logs_dirs();
Examples found in repository?
examples/struct_multiple.rs (line 9)
3fn main() {
4    // NOTE: These will possibly be empty if not running under systemd
5    let dirs = SystemdDirs::new();
6    println!("runtime dir: {:?}", dirs.runtime_dirs());
7    println!("state dir: {:?}", dirs.state_dirs());
8    println!("cache dir: {:?}", dirs.cache_dirs());
9    println!("log dir: {:?}", dirs.logs_dirs());
10    println!("config dir: {:?}", dirs.config_dirs());
11}
Source

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

Returns the first logs directory as defined by LogsDirectory in the unit file.

If the environment variable LOGS_DIRECTORY was not set when SystemdDirs was created, it returns None. If it was set, it returns the first path in the colon-separated list. To get all paths, use Self::logs_dirs.

§Examples
let dirs = systemd_directories::SystemdDirs::new();
let logs_dir = dirs.logs_dir();
Examples found in repository?
examples/struct.rs (line 9)
3fn main() {
4    // NOTE: These will possibly be empty if not running under systemd
5    let dirs = SystemdDirs::new();
6    println!("runtime dir: {:?}", dirs.runtime_dir());
7    println!("state dir: {:?}", dirs.state_dir());
8    println!("cache dir: {:?}", dirs.cache_dir());
9    println!("log dir: {:?}", dirs.logs_dir());
10    println!("config dir: {:?}", dirs.config_dir());
11}
Source

pub fn config_dirs(&self) -> Vec<&Path>

Returns all configuration directories as defined by ConfigurationDirectory in the unit file.

If the environment variable CONFIGURATION_DIRECTORY was not set when SystemdDirs was created, it returns an empty vector. If it was set, it returns all paths in the colon-separated list. To get just the first path, use Self::config_dir.

§Examples
let dirs = systemd_directories::SystemdDirs::new();
let config_dirs = dirs.config_dirs();
Examples found in repository?
examples/struct_multiple.rs (line 10)
3fn main() {
4    // NOTE: These will possibly be empty if not running under systemd
5    let dirs = SystemdDirs::new();
6    println!("runtime dir: {:?}", dirs.runtime_dirs());
7    println!("state dir: {:?}", dirs.state_dirs());
8    println!("cache dir: {:?}", dirs.cache_dirs());
9    println!("log dir: {:?}", dirs.logs_dirs());
10    println!("config dir: {:?}", dirs.config_dirs());
11}
Source

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

Returns the first configuration directory as defined by ConfigurationDirectory in the unit file.

If the environment variable CONFIGURATION_DIRECTORY was not set when SystemdDirs was created, it returns None. If it was set, it returns the first path in the colon-separated list. To get all paths, use Self::config_dirs.

§Examples
let dirs = systemd_directories::SystemdDirs::new();
let config_dir = dirs.config_dir();
Examples found in repository?
examples/struct.rs (line 10)
3fn main() {
4    // NOTE: These will possibly be empty if not running under systemd
5    let dirs = SystemdDirs::new();
6    println!("runtime dir: {:?}", dirs.runtime_dir());
7    println!("state dir: {:?}", dirs.state_dir());
8    println!("cache dir: {:?}", dirs.cache_dir());
9    println!("log dir: {:?}", dirs.logs_dir());
10    println!("config dir: {:?}", dirs.config_dir());
11}

Trait Implementations§

Source§

impl Clone for SystemdDirs

Source§

fn clone(&self) -> SystemdDirs

Returns a duplicate 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 SystemdDirs

Source§

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

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

impl Default for SystemdDirs

Source§

fn default() -> Self

Returns the “default value” for a type. 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.