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§
Required Methods§
Sourcefn 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 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.
Trait Implementations§
Source§impl<Q, R> Storage for Box<dyn Storage<Query = Q, Record = R> + Send>
impl<Q, R> Storage for Box<dyn Storage<Query = Q, Record = R> + Send>
Source§type Query = Q
type Query = Q
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,
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,
Implementations on Foreign Types§
Source§impl<Q, R> Storage for Box<dyn Storage<Query = Q, Record = R> + Send>
impl<Q, R> Storage for Box<dyn Storage<Query = Q, Record = R> + Send>
type Query = Q
type Record = R
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,
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>
This implementation is usefull for using as a fake for testing. In production you are more
likely want to talk to a database.
impl<T> Storage for Vec<T>
This implementation is usefull for using as a fake for testing. In production you are more likely want to talk to a database.