KV

Struct KV 

Source
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>

Source

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
Hide additional 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}
Source

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
Hide additional 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}
Source

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
Hide additional 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}
Source

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
Hide additional 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}
Source

pub fn keys(&mut self) -> Result<Vec<K>, KVError>

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>

§

impl<K, V> Send for KV<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for KV<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for KV<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for KV<K, V>
where K: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.