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
impl MemoryBackend
pub fn start(buffer_size: usize) -> Self
pub fn start_default() -> Self
Trait Implementations§
Source§impl Clone for MemoryBackend
impl Clone for MemoryBackend
Source§fn clone(&self) -> MemoryBackend
fn clone(&self) -> MemoryBackend
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Provider for MemoryBackend
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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§
impl Freeze for MemoryBackend
impl !RefUnwindSafe for MemoryBackend
impl Send for MemoryBackend
impl Sync for MemoryBackend
impl Unpin for MemoryBackend
impl !UnwindSafe for MemoryBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more