Struct kv::Bucket

source ·
pub struct Bucket<'a, K: Key<'a>, V: Value>(/* private fields */);
Expand description

Provides typed access to the key/value store

Implementations§

source§

impl<'a, K: Key<'a>, V: Value> Bucket<'a, K, V>

source

pub fn contains(&self, key: &K) -> Result<bool, Error>

Returns true if the bucket contains the given key

source

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

Get the value associated with the specified key

source

pub fn set(&self, key: &K, value: &V) -> Result<Option<V>, Error>

Set the value associated with the specified key to the provided value

source

pub fn compare_and_swap( &self, key: &K, old: Option<&V>, value: Option<&V> ) -> Result<(), Error>

Set the value associated with the specified key to the provided value, only if the existing value matches the old parameter

source

pub fn remove(&self, key: &K) -> Result<Option<V>, Error>

Remove the value associated with the specified key from the database

source

pub fn iter(&self) -> Iter<K, V>

Get an iterator over keys/values

source

pub fn iter_range(&self, a: &K, b: &K) -> Result<Iter<K, V>, Error>

Get an iterator over keys/values in the specified range

source

pub fn iter_prefix(&self, a: &K) -> Result<Iter<K, V>, Error>

Iterate over keys/values with the specified prefix

source

pub fn batch(&self, batch: Batch<K, V>) -> Result<(), Error>

Apply batch update

source

pub fn watch_prefix(&self, prefix: Option<&K>) -> Result<Watch<K, V>, Error>

Get updates when a key with the given prefix is changed

source

pub fn transaction<A, E: From<Error>, F: Fn(Transaction<'_, '_, K, V>) -> Result<A, TransactionError<E>>>( &self, f: F ) -> Result<A, E>

Execute a transaction

source

pub fn transaction2<A, T: Key<'a>, U: Value, E: From<Error>, F: Fn(Transaction<'_, '_, K, V>, Transaction<'_, '_, T, U>) -> Result<A, TransactionError<E>>>( &self, other: &Bucket<'a, T, U>, f: F ) -> Result<A, E>

Create a transaction with access to two buckets

source

pub fn transaction3<A, T: Key<'a>, U: Value, X: Key<'a>, Y: Value, E: From<Error>, F: Fn(Transaction<'_, '_, K, V>, Transaction<'_, '_, T, U>, Transaction<'_, '_, X, Y>) -> Result<A, TransactionError<E>>>( &self, other: &Bucket<'a, T, U>, other1: &Bucket<'a, X, Y>, f: F ) -> Result<A, E>

Create a transaction with access to three buckets

source

pub fn prev_key(&self, key: &K) -> Result<Option<Item<K, V>>, Error>

Get previous key and value in order, if one exists

source

pub fn next_key(&self, key: &K) -> Result<Option<Item<K, V>>, Error>

Get next key and value in order, if one exists

source

pub fn flush(&self) -> Result<usize, Error>

Flush to disk

source

pub async fn flush_async(&self) -> Result<usize, Error>

Flush to disk

source

pub fn pop_back(&self) -> Result<Option<Item<K, V>>, Error>

Remove and return the last item

source

pub fn pop_front(&self) -> Result<Option<Item<K, V>>, Error>

Remove and return the first item

source

pub fn first(&self) -> Result<Option<Item<K, V>>, Error>

Get the first item

source

pub fn last(&self) -> Result<Option<Item<K, V>>, Error>

Get the last item

source

pub fn len(&self) -> usize

Get the number of items

source

pub fn is_empty(&self) -> bool

Returns true when there are no items

source

pub fn clear(&self) -> Result<(), Error>

Remove all items

source

pub fn checksum(&self) -> Result<u32, Error>

CRC32 checksum of all keys and values

Trait Implementations§

source§

impl<'a, K: Clone + Key<'a>, V: Clone + Value> Clone for Bucket<'a, K, V>

source§

fn clone(&self) -> Bucket<'a, K, V>

Returns a copy 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<'a, K, V> !RefUnwindSafe for Bucket<'a, K, V>

§

impl<'a, K, V> Send for Bucket<'a, K, V>where K: Send, V: Send,

§

impl<'a, K, V> Sync for Bucket<'a, K, V>where K: Sync, V: Sync,

§

impl<'a, K, V> Unpin for Bucket<'a, K, V>where K: Unpin, V: Unpin,

§

impl<'a, K, V> !UnwindSafe for Bucket<'a, K, V>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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.
§

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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.