Struct KV

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

Source

pub fn new(p: &'static str) -> Result<KV<K, V>, PersyError>

Creates a new instance of the KV store

Examples found in repository?
examples/custom_types.rs (line 20)
18fn main() {
19    let cab_path = "./db.cab";
20    let mut test_store = KV::<MyKey, MyValue>::new(cab_path).unwrap();
21
22    let _ = test_store.insert(MyKey::Int(1i32), MyValue::String("value".to_string()));
23    println!("{:?}", test_store.get(&MyKey::Int(1i32)));
24    let _ = test_store.remove(&MyKey::Int(1i32));
25
26    // clean up the cab
27    let _ = std::fs::remove_file(cab_path);
28}
More examples
Hide additional 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}
Source

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?
examples/custom_types.rs (line 22)
18fn main() {
19    let cab_path = "./db.cab";
20    let mut test_store = KV::<MyKey, MyValue>::new(cab_path).unwrap();
21
22    let _ = test_store.insert(MyKey::Int(1i32), MyValue::String("value".to_string()));
23    println!("{:?}", test_store.get(&MyKey::Int(1i32)));
24    let _ = test_store.remove(&MyKey::Int(1i32));
25
26    // clean up the cab
27    let _ = std::fs::remove_file(cab_path);
28}
More examples
Hide additional 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}
Source

pub fn get(&mut self, key: &K) -> Result<Option<V>, PersyError>

Get the value from a key

Examples found in repository?
examples/custom_types.rs (line 23)
18fn main() {
19    let cab_path = "./db.cab";
20    let mut test_store = KV::<MyKey, MyValue>::new(cab_path).unwrap();
21
22    let _ = test_store.insert(MyKey::Int(1i32), MyValue::String("value".to_string()));
23    println!("{:?}", test_store.get(&MyKey::Int(1i32)));
24    let _ = test_store.remove(&MyKey::Int(1i32));
25
26    // clean up the cab
27    let _ = std::fs::remove_file(cab_path);
28}
More examples
Hide additional 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}
Source

pub fn remove(&mut self, key: &K) -> PRes<bool>

Removes a key and associated value from the key-value Store

Examples found in repository?
examples/custom_types.rs (line 24)
18fn main() {
19    let cab_path = "./db.cab";
20    let mut test_store = KV::<MyKey, MyValue>::new(cab_path).unwrap();
21
22    let _ = test_store.insert(MyKey::Int(1i32), MyValue::String("value".to_string()));
23    println!("{:?}", test_store.get(&MyKey::Int(1i32)));
24    let _ = test_store.remove(&MyKey::Int(1i32));
25
26    // clean up the cab
27    let _ = std::fs::remove_file(cab_path);
28}
More examples
Hide additional 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}
Source

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>

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V