pub struct KV<K, V> { /* private fields */ }Expand description
The type that represents the key-value store
Implementations§
Source§impl<K: Clone + Serialize + Deserialize + Eq + Hash, V: Clone + Serialize + Deserialize> KV<K, V>
impl<K: Clone + Serialize + Deserialize + Eq + Hash, V: Clone + Serialize + Deserialize> KV<K, V>
Sourcepub fn new(p: &'static str) -> Result<KV<K, V>, KVError>
pub fn new(p: &'static str) -> Result<KV<K, V>, KVError>
Creates a new instance of the KV store
Examples found in repository?
examples/custom_types.rs (line 22)
20fn main() {
21 let cab_path = "./db.cab";
22 let mut test_store = KV::<MyKey, MyValue>::new(cab_path).unwrap();
23
24 let _ = test_store.insert(MyKey::Int(1i32), MyValue::String("value".to_string()));
25 println!("{:?}", test_store.get(MyKey::Int(1i32)));
26 let _ = test_store.remove(MyKey::Int(1i32));
27
28
29 // clean up the cab
30 let _ = std::fs::remove_file(cab_path);
31}More examples
examples/main.rs (line 7)
5fn main() {
6 let cab_path = "./db.cab";
7 let mut test_store = KV::<String, Value>::new(cab_path).unwrap();
8
9 let _ = test_store.insert("key".to_string(), Value::String("value".to_string()));
10 println!("{:?}", test_store.get("key".to_string()).unwrap());
11 let _ = test_store.remove("key".to_string());
12
13 let _ = KV::<String, Value>::new(cab_path)
14 .unwrap()
15 .insert("key".to_string(), Value::String("value".to_string()));
16
17 let _ = KV::<String, Value>::new(cab_path)
18 .unwrap()
19 .remove("key".to_string());
20
21 let _ = std::fs::remove_file(cab_path);
22}Sourcepub fn insert(&mut self, key: K, value: V) -> Result<bool, KVError>
pub fn insert(&mut self, key: K, value: V) -> Result<bool, KVError>
Inserta a key, value pair into the key-value store
Examples found in repository?
examples/custom_types.rs (line 24)
20fn main() {
21 let cab_path = "./db.cab";
22 let mut test_store = KV::<MyKey, MyValue>::new(cab_path).unwrap();
23
24 let _ = test_store.insert(MyKey::Int(1i32), MyValue::String("value".to_string()));
25 println!("{:?}", test_store.get(MyKey::Int(1i32)));
26 let _ = test_store.remove(MyKey::Int(1i32));
27
28
29 // clean up the cab
30 let _ = std::fs::remove_file(cab_path);
31}More examples
examples/main.rs (line 9)
5fn main() {
6 let cab_path = "./db.cab";
7 let mut test_store = KV::<String, Value>::new(cab_path).unwrap();
8
9 let _ = test_store.insert("key".to_string(), Value::String("value".to_string()));
10 println!("{:?}", test_store.get("key".to_string()).unwrap());
11 let _ = test_store.remove("key".to_string());
12
13 let _ = KV::<String, Value>::new(cab_path)
14 .unwrap()
15 .insert("key".to_string(), Value::String("value".to_string()));
16
17 let _ = KV::<String, Value>::new(cab_path)
18 .unwrap()
19 .remove("key".to_string());
20
21 let _ = std::fs::remove_file(cab_path);
22}Sourcepub fn get(&mut self, key: K) -> Result<Option<V>, KVError>
pub fn get(&mut self, key: K) -> Result<Option<V>, KVError>
Get the value from a key
Examples found in repository?
examples/custom_types.rs (line 25)
20fn main() {
21 let cab_path = "./db.cab";
22 let mut test_store = KV::<MyKey, MyValue>::new(cab_path).unwrap();
23
24 let _ = test_store.insert(MyKey::Int(1i32), MyValue::String("value".to_string()));
25 println!("{:?}", test_store.get(MyKey::Int(1i32)));
26 let _ = test_store.remove(MyKey::Int(1i32));
27
28
29 // clean up the cab
30 let _ = std::fs::remove_file(cab_path);
31}More examples
examples/main.rs (line 10)
5fn main() {
6 let cab_path = "./db.cab";
7 let mut test_store = KV::<String, Value>::new(cab_path).unwrap();
8
9 let _ = test_store.insert("key".to_string(), Value::String("value".to_string()));
10 println!("{:?}", test_store.get("key".to_string()).unwrap());
11 let _ = test_store.remove("key".to_string());
12
13 let _ = KV::<String, Value>::new(cab_path)
14 .unwrap()
15 .insert("key".to_string(), Value::String("value".to_string()));
16
17 let _ = KV::<String, Value>::new(cab_path)
18 .unwrap()
19 .remove("key".to_string());
20
21 let _ = std::fs::remove_file(cab_path);
22}Sourcepub fn remove(&mut self, key: K) -> Result<bool, KVError>
pub fn remove(&mut self, key: K) -> Result<bool, KVError>
Removes a key and associated value from the key-value Store
Examples found in repository?
examples/custom_types.rs (line 26)
20fn main() {
21 let cab_path = "./db.cab";
22 let mut test_store = KV::<MyKey, MyValue>::new(cab_path).unwrap();
23
24 let _ = test_store.insert(MyKey::Int(1i32), MyValue::String("value".to_string()));
25 println!("{:?}", test_store.get(MyKey::Int(1i32)));
26 let _ = test_store.remove(MyKey::Int(1i32));
27
28
29 // clean up the cab
30 let _ = std::fs::remove_file(cab_path);
31}More examples
examples/main.rs (line 11)
5fn main() {
6 let cab_path = "./db.cab";
7 let mut test_store = KV::<String, Value>::new(cab_path).unwrap();
8
9 let _ = test_store.insert("key".to_string(), Value::String("value".to_string()));
10 println!("{:?}", test_store.get("key".to_string()).unwrap());
11 let _ = test_store.remove("key".to_string());
12
13 let _ = KV::<String, Value>::new(cab_path)
14 .unwrap()
15 .insert("key".to_string(), Value::String("value".to_string()));
16
17 let _ = KV::<String, Value>::new(cab_path)
18 .unwrap()
19 .remove("key".to_string());
20
21 let _ = std::fs::remove_file(cab_path);
22}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