Manager

Struct Manager 

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

Configuration manager.

§Example

use configory::Manager;

let manager = Manager::new("configory", ()).unwrap();
manager.set(&["option"], 3);

assert_eq!(manager.get::<_, i32>(&["option"]), Ok(Some(3)));

Implementations§

Source§

impl Manager

Source

pub fn new<S: AsRef<str>, E, D>( namespace: S, event_handler: E, ) -> Result<Self, Error>

Initialize the configuration manager.

This will spawn multiple background threads and create socket files. See Self::with_options to control the enabled features.

§Example
use configory::Manager;

let manager = Manager::new("configory", ()).unwrap();
Source

pub fn with_options<E, D>( options: &Options<'_>, event_handler: E, ) -> Result<Self, Error>

Initialize the configuration manager with some features disabled.

See Self::new if you want all the features available.

§Example
use configory::{Manager, Options};

// Create a config without IPC.
let options = Options::new("configory").notify(true);
let manager = Manager::with_options(&options, ()).unwrap();
Source

pub fn ipc(&self) -> Option<&Ipc>

Get an IPC handle.

Will be None only if IPC was disabled using Self::with_options.

§Example
use configory::{Manager, Options};

let manager = Manager::new("configory", ()).unwrap();
assert!(manager.ipc().is_some());

let options = Options::new("configory");
let manager = Manager::with_options(&options, ()).unwrap();
assert!(manager.ipc().is_none());

Methods from Deref<Target = Config>§

Source

pub fn get<'de, S, T>(&self, path: &[S]) -> Result<Option<T>, Error>
where S: AsRef<str>, T: Deserialize<'de>,

Get the current value of a config option.

This will return Ok(None) if the requested option does not exist, and an error if it does not match the requested type. This will never error if T is toml::Value.

§Example
use configory::Manager;

let manager = Manager::new("configory", ()).unwrap();
manager.set(&["option"], 3);

let existing_value = manager.get::<_, i32>(&["option"]);
let missing_value = manager.get::<_, i32>(&["missing"]);

assert_eq!(existing_value, Ok(Some(3)));
assert_eq!(missing_value, Ok(None));
Source

pub fn set<S, V>(&self, path: &[S], value: V)
where S: AsRef<str>, V: Into<Value>,

Set a runtime override for a config option.

See Self::reset for clearing runtime overrides.

§Example
use configory::Manager;

let manager = Manager::new("configory", ()).unwrap();

manager.set(&["option"], 3);
Source

pub fn reset<S>(&self, path: &[S])
where S: AsRef<str>,

Clear the runtime override for a config option.

See Self::set for setting runtime overrides.

§Example
use configory::Manager;

let manager = Manager::new("configory", ()).unwrap();

assert_eq!(manager.get::<_, i32>(&["option"]), Ok(Some(3)));
manager.reset(&["option"]);
assert_eq!(manager.get::<_, i32>(&["option"]), Ok(None));
Source

pub fn persist(&self) -> Result<(), Error>

Persist the current runtime config to the config file.

§Example
use configory::Manager;


let manager = Manager::new("configory", ()).unwrap();
manager.set(&["option"], 3);
manager.persist().unwrap();

Trait Implementations§

Source§

impl Deref for Manager

Source§

type Target = Config

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.