Struct slate::Slate
[−]
[src]
pub struct Slate<'s> { pub config: &'s Config, }
The main Key-Value structure.
Fields
config: &'s Config
Methods
impl<'s> Slate<'s>
[src]
fn filepath(&self) -> &PathBuf
[src]
fn set(&self, key: &String, value: &String) -> SlateResult<()>
[src]
Set a key with its value.
Example
use slate::config::Config; use slate::Slate; use std::env; let mut temp = env::temp_dir(); temp.push(".slate"); let config = Config { filepath: temp }; let slate: Slate = From::from(&config); let key = "foo".to_string(); let value = "bar".to_string(); match slate.set(&key, &value) { Ok(_) => println!("Saved"), Err(e) => panic!("{}", e), };
fn get(&self, key: &String) -> SlateResult<String>
[src]
Get the value of a key
Example
use slate::config::Config; use slate::Slate; use std::env; let mut temp = env::temp_dir(); temp.push(".slate"); let config = Config { filepath: temp }; let slate: Slate = From::from(&config); let key = "foo".to_string(); match slate.get(&key) { Ok(value) => println!("{}", value), //=> bar Err(e) => panic!("{}", e), };
fn remove(&self, key: &String) -> SlateResult<()>
[src]
Remove completely a key with its value.
Example
use slate::config::Config; use slate::Slate; use std::env; let mut temp = env::temp_dir(); temp.push(".slate"); let config = Config { filepath: temp }; let slate: Slate = From::from(&config); let key = "foo".to_string(); match slate.remove(&key) { Ok(_) => println!("Key removed"), Err(e) => panic!("{}", e), };
fn clear(&self) -> SlateResult<()>
[src]
Remove all keys.
Example
use slate::config::Config; use slate::Slate; use std::env; let mut temp = env::temp_dir(); temp.push(".slate"); let config = Config { filepath: temp }; let slate: Slate = From::from(&config); match slate.clear() { Ok(_) => println!("Keys removed"), Err(e) => panic!("{}", e), };
fn rename(&self, src: &String, dts: &String) -> SlateResult<()>
[src]
Rename a key.
Example
use slate::config::Config; use slate::Slate; use std::env; let mut temp = env::temp_dir(); temp.push(".slate"); let config = Config { filepath: temp }; let slate: Slate = From::from(&config); let old = "foo".to_string(); let new = "bar".to_string(); match slate.rename(&old, &new) { Ok(_) => println!("Renamed!"), Err(e) => panic!("{}", e), };
fn list(&self) -> SlateResult<Vec<String>>
[src]
Get a list of all keys.
Example
use slate::config::Config; use slate::Slate; use std::env; let mut temp = env::temp_dir(); temp.push(".slate"); let config = Config { filepath: temp }; let slate: Slate = From::from(&config); let list = match slate.list() { Ok(all) => all, Err(e) => panic!("{}", e), }; for key in &list { println!("{}", key); }
Trait Implementations
impl<'s> Clone for Slate<'s>
[src]
fn clone(&self) -> Slate<'s>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more