Store

Trait Store 

Source
pub trait Store:
    Clone
    + Send
    + Sync {
    type Error: Debug;
    type Key: Send + Clone;
    type Value: Value;
    type Count: Send + Clone;

    // Required methods
    fn incr_by<'life0, 'async_trait>(
        &'life0 self,
        key: Self::Key,
        val: Self::Count,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Value, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn incr<'life0, 'async_trait>(
        &'life0 self,
        key: Self::Key,
    ) -> Pin<Box<dyn Future<Output = Result<Self::Value, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn del<'life0, 'async_trait>(
        &'life0 self,
        key: Self::Key,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Self::Value>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn clear<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Store indicates the location and method of caching, such as storing in memory ([MemStore]) in the form of a HashMap or in Redis in the form of key-value pairs.

All methods are implemented in an async manner.

Store can be Clone, use Arc to store it.

Required Associated Types§

Source

type Error: Debug

[Error] represents possible errors that may occur during the execution of a function.

Source

type Key: Send + Clone

[Key] is used to denote the index type in key-value pairs.

Source

type Value: Value

Value is a structure used to represent values, such as the current count and the initial time.

Source

type Count: Send + Clone

Alias of Value::Count.

Required Methods§

Source

fn incr_by<'life0, 'async_trait>( &'life0 self, key: Self::Key, val: Self::Count, ) -> Pin<Box<dyn Future<Output = Result<Self::Value, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

The [incr_by] function takes a [Key] and an unsigned integer, indicating the amount by which the index should be incremented.

The function returns the result of the incremented count.

Source

fn incr<'life0, 'async_trait>( &'life0 self, key: Self::Key, ) -> Pin<Box<dyn Future<Output = Result<Self::Value, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

The [incr] function is a wrapper for the [incr_by] function, with val = 1.

Source

fn del<'life0, 'async_trait>( &'life0 self, key: Self::Key, ) -> Pin<Box<dyn Future<Output = Result<Option<Self::Value>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

The [del] function deletes the storage of the index [Key] and returns the count result before deletion.

Source

fn clear<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

The [clear] function clears all cached data.

This function is not mandatory; if Store does not need to clear cached data (for example, when stored in Redis or a relational database, bulk clearing of data is slow and unnecessary), the function can do nothing.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<'a, T: Store> Store for &'a T

Source§

type Error = <T as Store>::Error

Source§

type Key = <T as Store>::Key

Source§

type Value = <T as Store>::Value

Source§

type Count = <T as Store>::Count

Source§

fn incr_by<'life0, 'async_trait>( &'life0 self, key: Self::Key, val: Self::Count, ) -> Pin<Box<dyn Future<Output = Result<Self::Value, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn incr<'life0, 'async_trait>( &'life0 self, key: Self::Key, ) -> Pin<Box<dyn Future<Output = Result<Self::Value, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn del<'life0, 'async_trait>( &'life0 self, key: Self::Key, ) -> Pin<Box<dyn Future<Output = Result<Option<Self::Value>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn clear<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

impl<T: Store> Store for Arc<T>

Source§

type Error = <T as Store>::Error

Source§

type Key = <T as Store>::Key

Source§

type Value = <T as Store>::Value

Source§

type Count = <T as Store>::Count

Source§

fn incr_by<'life0, 'async_trait>( &'life0 self, key: Self::Key, val: Self::Count, ) -> Pin<Box<dyn Future<Output = Result<Self::Value, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn incr<'life0, 'async_trait>( &'life0 self, key: Self::Key, ) -> Pin<Box<dyn Future<Output = Result<Self::Value, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn del<'life0, 'async_trait>( &'life0 self, key: Self::Key, ) -> Pin<Box<dyn Future<Output = Result<Option<Self::Value>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn clear<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Implementors§