Trait feattle::persist::Persist [−][src]
pub trait Persist {
type Error: 'static + Error + Send + Sync;
fn save_current<'life0, 'life1, 'async_trait>(
&'life0 self,
value: &'life1 CurrentValues
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait, Global>>
where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
fn load_current<'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<Option<CurrentValues>, Self::Error>> + Send + 'async_trait, Global>>
where
'life0: 'async_trait,
Self: 'async_trait;
fn save_history<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: &'life2 ValueHistory
) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait, Global>>
where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait;
fn load_history<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<Option<ValueHistory>, Self::Error>> + Send + 'async_trait, Global>>
where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
}
Expand description
Responsible for storing and loading data from a permanent storage.
Async
The methods on this trait are async and can be implemented with the help of the async_trait
crate:
use async_trait::async_trait;
use feattle_core::persist::*;
struct MyPersistenceLogic;
#[async_trait]
impl Persist for MyPersistenceLogic {
type Error = std::io::Error;
async fn save_current(&self, value: &CurrentValues) -> Result<(), Self::Error> {
unimplemented!()
}
async fn load_current(&self) -> Result<Option<CurrentValues>, Self::Error> {
unimplemented!()
}
async fn save_history(&self, key: &str, value: &ValueHistory) -> Result<(), Self::Error> {
unimplemented!()
}
async fn load_history(&self, key: &str) -> Result<Option<ValueHistory>, Self::Error> {
unimplemented!()
}
}
Errors
The persistence layer can define their own error type, that will be bubbled up by other error
types, like super::UpdateError
and super::HistoryError
.
Associated Types
Required methods
Save current state of all feattles.
Load the current state of all feattles. With no previous state existed, Ok(None)
should be
returned.
Save the full history of a single feattle.
Load the full history of a single feattle. With the feattle has no history, Ok(None)
should be returned.