Struct crux_kv::KeyValue

source ·
pub struct KeyValue<Ev> { /* private fields */ }

Implementations§

source§

impl<Ev> KeyValue<Ev>
where Ev: 'static,

source

pub fn new(context: CapabilityContext<KeyValueOperation, Ev>) -> Self

source

pub fn get<F>(&self, key: String, make_event: F)
where F: FnOnce(Result<Option<Vec<u8>>, KeyValueError>) -> Ev + Send + Sync + 'static,

Read a value under key, will dispatch the event with a KeyValueResult::Get { value: Vec<u8> } as payload

source

pub async fn get_async( &self, key: String ) -> Result<Option<Vec<u8>>, KeyValueError>

Read a value under key, while in an async context. This is used together with crux_core::compose::Compose.

Returns the value stored under the key, or None if the key is not present.

source

pub fn set<F>(&self, key: String, value: Vec<u8>, make_event: F)
where F: FnOnce(Result<Option<Vec<u8>>, KeyValueError>) -> Ev + Send + Sync + 'static,

Set key to be the provided value. Typically the bytes would be a value serialized/deserialized by the app.

Will dispatch the event with a KeyValueResult::Set { previous: Vec<u8> } as payload

source

pub async fn set_async( &self, key: String, value: Vec<u8> ) -> Result<Option<Vec<u8>>, KeyValueError>

Set key to be the provided value, while in an async context. This is used together with crux_core::compose::Compose.

Returns the previous value stored under the key, if any.

source

pub fn delete<F>(&self, key: String, make_event: F)
where F: FnOnce(Result<Option<Vec<u8>>, KeyValueError>) -> Ev + Send + Sync + 'static,

Remove a key and its value, will dispatch the event with a KeyValueResult::Delete { previous: Vec<u8> } as payload

source

pub async fn delete_async( &self, key: String ) -> Result<Option<Vec<u8>>, KeyValueError>

Remove a key and its value, while in an async context. This is used together with crux_core::compose::Compose.

Returns the previous value stored under the key, if any.

source

pub fn exists<F>(&self, key: String, make_event: F)
where F: FnOnce(Result<bool, KeyValueError>) -> Ev + Send + Sync + 'static,

Check to see if a key exists, will dispatch the event with a KeyValueResult::Exists { is_present: bool } as payload

source

pub async fn exists_async(&self, key: String) -> Result<bool, KeyValueError>

Check to see if a key exists, while in an async context. This is used together with crux_core::compose::Compose.

Returns true if the key exists, false otherwise.

source

pub fn list_keys<F>(&self, prefix: String, cursor: u64, make_event: F)
where F: FnOnce(Result<(Vec<String>, u64), KeyValueError>) -> Ev + Send + Sync + 'static,

List keys that start with the provided prefix, starting from the provided cursor. Will dispatch the event with a KeyValueResult::ListKeys { keys: Vec<String>, cursor: u64 } as payload.

A cursor is an opaque value that points to the first key in the next page of keys.

If the cursor is not found for the specified prefix, the response will include a KeyValueError::CursorNotFound error.

If the cursor is found the result will be a tuple of the keys and the next cursor (if there are more keys to list, the cursor will be non-zero, otherwise it will be zero)

source

pub async fn list_keys_async( &self, prefix: String, cursor: u64 ) -> Result<(Vec<String>, u64), KeyValueError>

List keys that start with the provided prefix, starting from the provided cursor, while in an async context. This is used together with crux_core::compose::Compose.

A cursor is an opaque value that points to the first key in the next page of keys.

If the cursor is not found for the specified prefix, the response will include a KeyValueError::CursorNotFound error.

If the cursor is found the result will be a tuple of the keys and the next cursor (if there are more keys to list, the cursor will be non-zero, otherwise it will be zero)

Trait Implementations§

source§

impl<Ev> Capability<Ev> for KeyValue<Ev>

§

type Operation = KeyValueOperation

§

type MappedSelf<MappedEv> = KeyValue<MappedEv>

source§

fn map_event<F, NewEv>(&self, f: F) -> Self::MappedSelf<NewEv>
where F: Fn(NewEv) -> Ev + Send + Sync + 'static, Ev: 'static, NewEv: 'static,

source§

impl<Ev> Clone for KeyValue<Ev>

source§

fn clone(&self) -> Self

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<Ev> Freeze for KeyValue<Ev>

§

impl<Ev> !RefUnwindSafe for KeyValue<Ev>

§

impl<Ev> Send for KeyValue<Ev>

§

impl<Ev> Sync for KeyValue<Ev>

§

impl<Ev> Unpin for KeyValue<Ev>

§

impl<Ev> !UnwindSafe for KeyValue<Ev>

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> ToOwned for T
where 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 T
where 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 T
where 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.