Config

Struct Config 

Source
pub struct Config {
    pub path: PathBuf,
    /* private fields */
}

Fields§

§path: PathBuf

Implementations§

Source§

impl Config

Source

pub fn new<T: AsRef<str>>(name: T) -> Result<Self>

Create a new system config.

Examples found in repository?
examples/write.rs (line 4)
3fn main() {
4    let mut config = Config::new("system-config-example").unwrap();
5
6    config.insert("key1", "value1");
7    config.insert("key2", "value2");
8
9    config.write().unwrap();
10}
More examples
Hide additional examples
examples/read.rs (line 4)
3fn main() {
4    let config = Config::new("system-config-example").unwrap();
5
6    let key1 = config.get("key1").unwrap();
7    let key2 = config.get("key2").unwrap();
8
9    println!("key1: {}", key1);
10    println!("key2: {}", key2);
11}
examples/multiple.rs (line 12)
11fn write() {
12    let mut config = Config::new("system-config-multiple-example").unwrap();
13
14    config.write_insert("1", "value 1").unwrap();
15    config.write_insert("2", "value 2").unwrap();
16    config.write_insert("3", "value 3").unwrap();
17
18    println!("wrote:\n  1    value 1\n  2    value 2\n  3    value 3\n");
19}
20
21fn read() {
22    let mut config = Config::new("system-config-multiple-example").unwrap();
23
24    let x1 = config.read_get("1").unwrap().unwrap();
25    let x2 = config.read_get("2").unwrap().unwrap();
26    let x3 = config.read_get("3").unwrap().unwrap();
27
28    println!("read:\n  1    {}\n  2    {}\n  3    {}\n", x1, x2, x3);
29}
Source

pub fn write_clear_by_name<T: AsRef<str>>(name: T) -> Result<()>

Clear a config by name and sync it with the disk.

Examples found in repository?
examples/clear.rs (line 4)
3fn main() {
4    Config::write_clear_by_name("system-config-example").unwrap();
5    Config::write_clear_by_name("system-config-multiple-example").unwrap();
6}
Source

pub fn read(&mut self) -> Result<()>

Update the config from disk.

Source

pub fn write(&self) -> Result<()>

Update the disk from the config.

Examples found in repository?
examples/write.rs (line 9)
3fn main() {
4    let mut config = Config::new("system-config-example").unwrap();
5
6    config.insert("key1", "value1");
7    config.insert("key2", "value2");
8
9    config.write().unwrap();
10}
Source

pub fn insert<T: AsRef<str>>(&mut self, key: T, value: T)

Insert a key-value pair into the config.

Examples found in repository?
examples/write.rs (line 6)
3fn main() {
4    let mut config = Config::new("system-config-example").unwrap();
5
6    config.insert("key1", "value1");
7    config.insert("key2", "value2");
8
9    config.write().unwrap();
10}
Source

pub fn get<T: AsRef<str>>(&self, query: T) -> Option<String>

Get a value for a key.

Examples found in repository?
examples/read.rs (line 6)
3fn main() {
4    let config = Config::new("system-config-example").unwrap();
5
6    let key1 = config.get("key1").unwrap();
7    let key2 = config.get("key2").unwrap();
8
9    println!("key1: {}", key1);
10    println!("key2: {}", key2);
11}
Source

pub fn clear(&mut self)

Clear all data in the config.

Source

pub fn write_insert<T: AsRef<str>>(&mut self, key: T, value: T) -> Result<()>

Insert a key-value pair into the config and write to disk.

Examples found in repository?
examples/multiple.rs (line 14)
11fn write() {
12    let mut config = Config::new("system-config-multiple-example").unwrap();
13
14    config.write_insert("1", "value 1").unwrap();
15    config.write_insert("2", "value 2").unwrap();
16    config.write_insert("3", "value 3").unwrap();
17
18    println!("wrote:\n  1    value 1\n  2    value 2\n  3    value 3\n");
19}
Source

pub fn read_get<T: AsRef<str>>(&mut self, query: T) -> Result<Option<String>>

Read the system config and get a value for a key.

Examples found in repository?
examples/multiple.rs (line 24)
21fn read() {
22    let mut config = Config::new("system-config-multiple-example").unwrap();
23
24    let x1 = config.read_get("1").unwrap().unwrap();
25    let x2 = config.read_get("2").unwrap().unwrap();
26    let x3 = config.read_get("3").unwrap().unwrap();
27
28    println!("read:\n  1    {}\n  2    {}\n  3    {}\n", x1, x2, x3);
29}
Source

pub fn write_clear(&mut self) -> Result<()>

Clear all data in the config and write to disk.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

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 Config

Source§

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

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

impl PartialEq for Config

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Config

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

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.