Struct slate::Slate
[−]
[src]
pub struct Slate { pub filepath: PathBuf, }
The main Key-Value structure.
Fields
filepath: PathBuf
Where the file containing the data is.
Methods
impl Slate
[src]
fn set(&self, key: &String, value: &String) -> Result<(), &'static str>
Set a key with its value.
Example
use slate::Slate; use std::env; // Create a temporal file for // the example. You can use Default::default(); // to create the Slate and skip this part. let mut temp = env::temp_dir(); temp.push(".slate"); let slate: Slate = Slate { filepath: temp }; 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) -> Result<String, &'static str>
Get the value of a key
Example
use slate::Slate; use std::env; // Create a temporal file for // the example. You can use Default::default(); // to create the Slate and skip this part. let mut temp = env::temp_dir(); temp.push(".slate"); let slate: Slate = Slate { filepath: temp }; let key = "foo".to_string(); match slate.get(&key) { Ok(value) => println!("{}", value), //=> bar Err(e) => panic!("{}", e), };
fn remove(&self, key: &String) -> Result<(), &'static str>
Remove completely a key with its value.
Example
use slate::Slate; use std::env; // Create a temporal file for // the example. You can use Default::default(); // to create the Slate and skip this part. let mut temp = env::temp_dir(); temp.push(".slate"); let slate: Slate = Slate { filepath: temp }; let key = "foo".to_string(); match slate.remove(&key) { Ok(_) => println!("Key removed"), Err(e) => panic!("{}", e), };
fn clear(&self) -> Result<(), &'static str>
Remove all keys.
Example
use slate::Slate; use std::env; // Create a temporal file for // the example. You can use Default::default(); // to create the Slate and skip this part. let mut temp = env::temp_dir(); temp.push(".slate"); let slate: Slate = Slate { filepath: temp }; match slate.clear() { Ok(_) => println!("Keys removed"), Err(e) => panic!("{}", e), };
fn rename(&self, src: &String, dts: &String) -> Result<(), &'static str>
Rename a key.
Example
use slate::Slate; use std::env; // Create a temporal file for // the example. You can use Default::default(); // to create the Slate and skip this part. let mut temp = env::temp_dir(); temp.push(".slate"); let slate: Slate = Slate { filepath: temp }; 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) -> Result<Vec<String>, &'static str>
Get a list of all keys.
Example
use slate::Slate; use std::env; // Create a temporal file for // the example. You can use Default::default(); // to create the Slate and skip this part. let mut temp = env::temp_dir(); temp.push(".slate"); let slate: Slate = Slate { filepath: temp }; let list = match slate.list() { Ok(all) => all, Err(e) => panic!("{}", e), }; for key in &list { println!("{}", key); }