pub struct KeyValue<Ev> { /* private fields */ }
Implementations§
Source§impl<Ev> KeyValue<Ev>where
Ev: 'static,
impl<Ev> KeyValue<Ev>where
Ev: 'static,
pub fn new(context: CapabilityContext<KeyValueOperation, Ev>) -> Self
Sourcepub fn get<F>(&self, key: String, make_event: F)
pub fn get<F>(&self, key: String, make_event: F)
Read a value under key
, will dispatch the event with a
KeyValueResult::Get { value: Vec<u8> }
as payload
Sourcepub async fn get_async(
&self,
key: String,
) -> Result<Option<Vec<u8>>, KeyValueError>
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.
Sourcepub fn set<F>(&self, key: String, value: Vec<u8>, make_event: F)
pub fn set<F>(&self, key: String, value: Vec<u8>, make_event: F)
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
Sourcepub async fn set_async(
&self,
key: String,
value: Vec<u8>,
) -> Result<Option<Vec<u8>>, KeyValueError>
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.
Sourcepub fn delete<F>(&self, key: String, make_event: F)
pub fn delete<F>(&self, key: String, make_event: F)
Remove a key
and its value, will dispatch the event with a
KeyValueResult::Delete { previous: Vec<u8> }
as payload
Sourcepub async fn delete_async(
&self,
key: String,
) -> Result<Option<Vec<u8>>, KeyValueError>
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.
Sourcepub fn exists<F>(&self, key: String, make_event: F)
pub fn exists<F>(&self, key: String, make_event: F)
Check to see if a key
exists, will dispatch the event with a
KeyValueResult::Exists { is_present: bool }
as payload
Sourcepub async fn exists_async(&self, key: String) -> Result<bool, KeyValueError>
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.
Sourcepub fn list_keys<F>(&self, prefix: String, cursor: u64, make_event: F)
pub fn list_keys<F>(&self, prefix: String, cursor: u64, make_event: F)
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)
Sourcepub async fn list_keys_async(
&self,
prefix: String,
cursor: u64,
) -> Result<(Vec<String>, u64), KeyValueError>
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)