[][src]Struct configstore::Configstore

pub struct Configstore { /* fields omitted */ }

Configstore store configurations Will store configuration on your platforms native configuration directory

Examples

use configstore::{Configstore, AppUI};

let config_store = Configstore::new("myApp", AppUI::CommandLine).unwrap();
config_store.set("key", "value".to_string()).unwrap();
let value: String = config_store.get("key").unwrap();
assert_eq!("value".to_string(), value);

Implementations

impl Configstore[src]

pub fn new(app_name: &str, app_ui: AppUI) -> Result<Self>[src]

Creates a new configstore based on a name and a type of ui Takes: app_name: &str representing the name of the application app_ui: AppUI (either AppUI::CommandLine or AppUI::Graphical) type of the application

Examples

use configstore::{Configstore, AppUI};

let command_line_confg = Configstore::new("myApp", AppUI::CommandLine).unwrap();

Errors

Could error either if your plateform does not have a config directory (All Linux, MacOs and Windows do) Or if the application is unable to create the directories for its config files

pub fn set<T>(&self, key: &str, value: T) -> Result<()> where
    T: Serialize + for<'de> Deserialize<'de>, 
[src]

Sets a value in the configstore, to be retrieved at any point in time with get Overwrites any existing values with the same key, or creates a new pair value is saved as a json file in $CONFIG/configstore-rs/$APPNAME/key.json value must implement serde::Serialize and serde::Deserialize

Examples

use serde_derive::*;
use configstore::{Configstore, AppUI};
#[derive(Deserialize, Serialize, Eq, PartialEq, Debug, Clone)]
struct Value {
    text: String,
    num: u32
}

let config_store = Configstore::new("myApp", AppUI::CommandLine).unwrap();
let value = Value {text: "hello world".to_string(), num: 4343};
config_store.set("key", value.clone()).unwrap();
let same_value: Value = config_store.get("key").unwrap();
assert_eq!(value, same_value);

Errors

Possible errors if config file cannot be oppened, or value cannot be encoded into json

pub fn get<T>(&self, key: &str) -> Result<T> where
    T: Serialize + for<'de> Deserialize<'de>, 
[src]

Check the set docs for usage

Errors

Could produce errors if unable to open config file This could happen if the key was never set or if you manually deleted the file Otherwise could cause errors if the type cannot be decoded correctly

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.