Struct MemoryBackend

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

An implementation of ExpiryStore based on Arc-Mutex-Hashmap using tokio’s delayqueue for expiration.

§Example

use basteh::Basteh;
use basteh_memory::{MemoryBackend};

let provider = MemoryBackend::start_default();
let storage = Basteh::build().provider(provider).finish();

Implementations§

Source§

impl MemoryBackend

Source

pub fn start(buffer_size: usize) -> Self

Source

pub fn start_default() -> Self

Trait Implementations§

Source§

impl Clone for MemoryBackend

Source§

fn clone(&self) -> MemoryBackend

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

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

Performs copy-assignment from source. Read more
Source§

impl Provider for MemoryBackend

Source§

fn keys<'life0, 'life1, 'async_trait>( &'life0 self, scope: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Box<dyn Iterator<Item = Vec<u8>>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Set a key-value pair, if the key already exist, value should be overwritten
Source§

fn set<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, scope: &'life1 str, key: &'life2 [u8], value: Value<'life3>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Set a key-value pair, if the key already exist, value should be overwritten
Source§

fn get<'a, 'life0, 'life1, 'async_trait>( &'a self, scope: &'life0 str, key: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<Option<OwnedValue>>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a single value for specified key, it should return None if the value does not exist
Source§

fn get_range<'a, 'life0, 'life1, 'async_trait>( &'a self, scope: &'life0 str, key: &'life1 [u8], start: i64, end: i64, ) -> Pin<Box<dyn Future<Output = Result<Vec<OwnedValue>>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a list of values for specified key, it should return an empty vector if the value does not exist
Source§

fn push<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, scope: &'life1 str, key: &'life2 [u8], value: Value<'life3>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Push a value into the list associated with this key, if the key has a value of another type, it should return error
Source§

fn push_multiple<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, scope: &'life1 str, key: &'life2 [u8], value: Vec<Value<'life3>>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Push multiple values into the list associated with this key, if the key has a value of another type, it should return error
Source§

fn pop<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, scope: &'life1 str, key: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<Option<OwnedValue>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Pop a value from the list associated with this key, if the key has a value of another type, it should return error
Source§

fn mutate<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, scope: &'life1 str, key: &'life2 [u8], mutations: Mutation, ) -> Pin<Box<dyn Future<Output = Result<i64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Mutate and get a value for specified key, it should set the value to 0 if it doesn’t exist
Source§

fn remove<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, scope: &'life1 str, key: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<Option<OwnedValue>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Delete the key from storage, if the key doesn’t exist, it shouldn’t return an error
Source§

fn contains_key<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, scope: &'life1 str, key: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Check if key exist in storage
Source§

fn persist<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, scope: &'life1 str, key: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Remove all expiry requests from a key and make it persistent, the persistenty can be overwriten by calling expire on the key.
Source§

fn expire<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, scope: &'life1 str, key: &'life2 [u8], expire_in: Duration, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Sets an expiry for a key, the key may or may not be removed based on implementation, but it should be guaranteed that it won’t appear in get based methods or contains checks after the period specified.
Source§

fn expiry<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, scope: &'life1 str, key: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<Option<Duration>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Gets expiry for a key, returning None means it doesn’t have an expiry, if the provider can’t return an expiry, it should return an error instead. The result of this function can have some error, but it should be documented.
Source§

fn extend<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, scope: &'life1 str, key: &'life2 [u8], duration: Duration, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Extend expiry for a key for another duration of time. If the key doesn’t have an expiry, it should be equivalent of calling expire.
Source§

fn set_expiring<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, scope: &'life1 str, key: &'life2 [u8], value: Value<'life3>, expire_in: Duration, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Set a key-value for a duration of time, if the key already exists, it should overwrite both the value and the expiry for that key.
Source§

fn get_expiring<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, scope: &'life1 str, key: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<Option<(OwnedValue, Option<Duration>)>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Get the value and expiry for a key, it is possible to return None if the key doesn’t exist, or return None for the expiry if the key is persistent.

Auto Trait Implementations§

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