Trait Storage

Source
pub trait Storage {
    type Record;
    type Query;

    // Required methods
    fn save<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        records: &'life1 mut Vec<Self::Record>,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn load<'life0, 'async_trait>(
        &'life0 mut self,
        query: Self::Query,
    ) -> Pin<Box<dyn Future<Output = Vec<Self::Record>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Can save records asynchronously

Required Associated Types§

Source

type Record

Records saved in the storage

Source

type Query

Describes the desired data for the load operation. Usefull for e.g. applying filters.

Required Methods§

Source

fn save<'life0, 'life1, 'async_trait>( &'life0 mut self, records: &'life1 mut Vec<Self::Record>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Saves all the records to the persistence backend. Note that this method is infallible. This implies that the responsibility of handling errors lies with the implementation of this trait. So it is up to the implementation to decide how often to retry before (if ever) giving up. What to log and so on.

records contains all the records which are to be persisted with this call to save. The records are passed in a Vec rather than in a single call to enable bulk insertion. They are also passed in a Vec rather than a slice (&[Record]) in order to enable taking ownership of each record and avoid cloning. Finally it is a &mut Vec rather than a buffer so we can reuse it, without having to reallocate it a lot during the lifetime of our application.

Source

fn load<'life0, 'async_trait>( &'life0 mut self, query: Self::Query, ) -> Pin<Box<dyn Future<Output = Vec<Self::Record>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Load the contents of the storage as a list of records.

Trait Implementations§

Source§

impl<Q, R> Storage for Box<dyn Storage<Query = Q, Record = R> + Send>
where Q: Send, R: Send,

Source§

type Query = Q

Describes the desired data for the load operation. Usefull for e.g. applying filters.
Source§

type Record = R

Records saved in the storage
Source§

fn save<'life0, 'life1, 'async_trait>( &'life0 mut self, records: &'life1 mut Vec<R>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Saves all the records to the persistence backend. Note that this method is infallible. This implies that the responsibility of handling errors lies with the implementation of this trait. So it is up to the implementation to decide how often to retry before (if ever) giving up. What to log and so on. Read more
Source§

fn load<'life0, 'async_trait>( &'life0 mut self, query: Q, ) -> Pin<Box<dyn Future<Output = Vec<R>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Load the contents of the storage as a list of records.

Implementations on Foreign Types§

Source§

impl<Q, R> Storage for Box<dyn Storage<Query = Q, Record = R> + Send>
where Q: Send, R: Send,

Source§

type Query = Q

Source§

type Record = R

Source§

fn save<'life0, 'life1, 'async_trait>( &'life0 mut self, records: &'life1 mut Vec<R>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn load<'life0, 'async_trait>( &'life0 mut self, query: Q, ) -> Pin<Box<dyn Future<Output = Vec<R>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

impl<T> Storage for Vec<T>
where T: Send + Clone,

This implementation is usefull for using as a fake for testing. In production you are more likely want to talk to a database.

Source§

type Query = Range<usize>

Source§

type Record = T

Source§

fn save<'life0, 'life1, 'async_trait>( &'life0 mut self, records: &'life1 mut Vec<T>, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn load<'life0, 'async_trait>( &'life0 mut self, query: Range<usize>, ) -> Pin<Box<dyn Future<Output = Vec<T>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Implementors§