Skip to main content

Persistence

Trait Persistence 

Source
pub trait Persistence<ValueT, MetaDataT>: Send + Sync
where ValueT: Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static, MetaDataT: Clone + Default + Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static,
{ // Required methods fn init<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn update<'life0, 'async_trait>( &'life0 self, state: PersistentState<ValueT, MetaDataT>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn load<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<PersistentState<ValueT, MetaDataT>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn add_item<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, value: ValueT, strategy: Option<UpdateStrategy>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_item<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<ValueT>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn remove_item<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn list_keys<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn list_items<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ValueT>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; // Provided method fn merge<'life0, 'async_trait>( &'life0 self, state: PersistentState<ValueT, MetaDataT>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } }
Expand description

持久化抽象 trait 定义了状态持久化的核心接口,支持多状态管理

Required Methods§

Source

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

初始化

Source

fn update<'life0, 'async_trait>( &'life0 self, state: PersistentState<ValueT, MetaDataT>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

更新状态

Source

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

加载状态

Source

fn add_item<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, value: ValueT, strategy: Option<UpdateStrategy>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

添加新数据项

Source

fn get_item<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<ValueT>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

加载指定数据项

Source

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

删除数据项

Source

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

列出所有数据项键

Source

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

列出所有数据项

Provided Methods§

Source

fn merge<'life0, 'async_trait>( &'life0 self, state: PersistentState<ValueT, MetaDataT>, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

合并状态

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<V, M> Persistence<V, M> for SqliteBackend
where V: Clone + Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static, M: Clone + Default + Serialize + for<'de> Deserialize<'de> + Send + Sync + 'static,