pub struct KV<K, V> { /* private fields */ }
Expand description
The type that represents the key-value store
Implementations§
Source§impl<K, V> KV<K, V>where
K: Clone + Serialize + for<'kde> Deserialize<'kde> + Eq + Hash,
V: Clone + Serialize + for<'vde> Deserialize<'vde>,
impl<K, V> KV<K, V>where
K: Clone + Serialize + for<'kde> Deserialize<'kde> + Eq + Hash,
V: Clone + Serialize + for<'vde> Deserialize<'vde>,
Sourcepub fn new(p: &'static str) -> Result<KV<K, V>, PersyError>
pub fn new(p: &'static str) -> Result<KV<K, V>, PersyError>
Creates a new instance of the KV store
Examples found in repository?
More examples
examples/main.rs (line 5)
3fn main() {
4 let cab_path = "./db.cab";
5 let mut test_store = KV::<String, Value>::new(cab_path).unwrap();
6
7 let _ = test_store.insert("key".to_string(), Value::String("value".to_string()));
8 println!("{:?}", test_store.get(&"key".to_string()).unwrap());
9 let _ = test_store.remove(&"key".to_string());
10
11 let _ = KV::<String, Value>::new(cab_path)
12 .unwrap()
13 .insert("key".to_string(), Value::String("value".to_string()));
14
15 let _ = KV::<String, Value>::new(cab_path)
16 .unwrap()
17 .remove(&"key".to_string());
18
19 let _ = std::fs::remove_file(cab_path);
20}
Sourcepub fn insert(&mut self, key: K, value: V) -> PRes<bool>
pub fn insert(&mut self, key: K, value: V) -> PRes<bool>
Inserta a key, value pair into the key-value store
Examples found in repository?
More examples
examples/main.rs (line 7)
3fn main() {
4 let cab_path = "./db.cab";
5 let mut test_store = KV::<String, Value>::new(cab_path).unwrap();
6
7 let _ = test_store.insert("key".to_string(), Value::String("value".to_string()));
8 println!("{:?}", test_store.get(&"key".to_string()).unwrap());
9 let _ = test_store.remove(&"key".to_string());
10
11 let _ = KV::<String, Value>::new(cab_path)
12 .unwrap()
13 .insert("key".to_string(), Value::String("value".to_string()));
14
15 let _ = KV::<String, Value>::new(cab_path)
16 .unwrap()
17 .remove(&"key".to_string());
18
19 let _ = std::fs::remove_file(cab_path);
20}
Sourcepub fn get(&mut self, key: &K) -> Result<Option<V>, PersyError>
pub fn get(&mut self, key: &K) -> Result<Option<V>, PersyError>
Get the value from a key
Examples found in repository?
More examples
examples/main.rs (line 8)
3fn main() {
4 let cab_path = "./db.cab";
5 let mut test_store = KV::<String, Value>::new(cab_path).unwrap();
6
7 let _ = test_store.insert("key".to_string(), Value::String("value".to_string()));
8 println!("{:?}", test_store.get(&"key".to_string()).unwrap());
9 let _ = test_store.remove(&"key".to_string());
10
11 let _ = KV::<String, Value>::new(cab_path)
12 .unwrap()
13 .insert("key".to_string(), Value::String("value".to_string()));
14
15 let _ = KV::<String, Value>::new(cab_path)
16 .unwrap()
17 .remove(&"key".to_string());
18
19 let _ = std::fs::remove_file(cab_path);
20}
Sourcepub fn remove(&mut self, key: &K) -> PRes<bool>
pub fn remove(&mut self, key: &K) -> PRes<bool>
Removes a key and associated value from the key-value Store
Examples found in repository?
More examples
examples/main.rs (line 9)
3fn main() {
4 let cab_path = "./db.cab";
5 let mut test_store = KV::<String, Value>::new(cab_path).unwrap();
6
7 let _ = test_store.insert("key".to_string(), Value::String("value".to_string()));
8 println!("{:?}", test_store.get(&"key".to_string()).unwrap());
9 let _ = test_store.remove(&"key".to_string());
10
11 let _ = KV::<String, Value>::new(cab_path)
12 .unwrap()
13 .insert("key".to_string(), Value::String("value".to_string()));
14
15 let _ = KV::<String, Value>::new(cab_path)
16 .unwrap()
17 .remove(&"key".to_string());
18
19 let _ = std::fs::remove_file(cab_path);
20}
Sourcepub fn keys(&mut self) -> Result<Vec<K>, PersyError>
pub fn keys(&mut self) -> Result<Vec<K>, PersyError>
get all the keys contained in the KV Store
Auto Trait Implementations§
impl<K, V> Freeze for KV<K, V>
impl<K, V> RefUnwindSafe for KV<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for KV<K, V>
impl<K, V> Sync for KV<K, V>
impl<K, V> Unpin for KV<K, V>
impl<K, V> UnwindSafe for KV<K, V>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more