GrausDb

Struct GrausDb 

Source
pub struct GrausDb { /* private fields */ }
Expand description

The GrausDb stores string key/value pairs.

Key/value pairs are persisted to disk in log files. Log files are named after monotonically increasing generation numbers with a log extension name. A SkipMap in memory stores the keys and the value locations for fast query.

GrausDb is thead-safe. It can be cloned to use it on new threads.

use std::env::current_dir;

let store = GrausDb::open(current_dir()?)?;
store.set(b"key".to_vec(), b"value")?;
let val = store.get(b"key")?;
assert_eq!(val, Some(b"value".to_vec()));

Implementations§

Source§

impl GrausDb

Source

pub fn open(path: impl Into<PathBuf>) -> Result<GrausDb>

Opens a GrausDb with the given path.

This will create a new directory if the given one does not exist.

§Errors

It propagates I/O or deserialization errors during the log replay.

Source

pub fn set(&self, key: Vec<u8>, value: &[u8]) -> Result<()>

Sets the value of a string key to a string.

If the key already exists, the previous value will be overwritten.

Source

pub fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>

Gets the string value of a given string key.

Returns None if the given key does not exist.

Source

pub fn remove(&self, key: &[u8]) -> Result<()>

Removes a given key.

Returns GrausError::KeyNotFound if the key does not exist.

Source

pub fn update_if<F, P>( &self, key: Vec<u8>, update_fn: F, predicate_key: Option<&[u8]>, predicate: Option<P>, ) -> Result<()>
where F: FnOnce(&mut Vec<u8>), P: FnOnce(&[u8]) -> bool,

Updates atomically an existing value.

If predicate_key and predicate are provided, it won´t update the value if the predicate is not satisfied for predicate_key.

Trait Implementations§

Source§

impl Clone for GrausDb

Source§

fn clone(&self) -> GrausDb

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl !Freeze for GrausDb

§

impl !RefUnwindSafe for GrausDb

§

impl Send for GrausDb

§

impl !Sync for GrausDb

§

impl Unpin for GrausDb

§

impl !UnwindSafe for GrausDb

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.