[−][src]Struct configstore::Configstore
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]
T: Serialize + for<'de> Deserialize<'de>,
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]
T: Serialize + for<'de> Deserialize<'de>,
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
impl RefUnwindSafe for Configstore
impl Send for Configstore
impl Sync for Configstore
impl Unpin for Configstore
impl UnwindSafe for Configstore
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,