pub trait SessionStore: Send + Sync {
// Required methods
fn save<'life0, 'async_trait>(
&'life0 self,
session: SessionRecord,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn load<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
) -> Pin<Box<dyn Future<Output = Result<SessionRecord>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
Persists, loads, and deletes SessionRecords.
The runtime saves a record when a session starts, loads it to resume governance context, and deletes it when the session ends.
§Example
use aa_core::storage::{Result, SessionId, SessionRecord, SessionStore, StorageError};
use async_trait::async_trait;
/// A store that holds no sessions.
struct EmptySessionStore;
#[async_trait]
impl SessionStore for EmptySessionStore {
async fn save(&self, _session: SessionRecord) -> Result<()> {
Ok(())
}
async fn load(&self, session_id: &SessionId) -> Result<SessionRecord> {
Err(StorageError::NotFound(format!("{:?}", session_id.as_bytes())))
}
async fn delete(&self, _session_id: &SessionId) -> Result<()> {
Ok(())
}
}Required Methods§
Sourcefn save<'life0, 'async_trait>(
&'life0 self,
session: SessionRecord,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn save<'life0, 'async_trait>(
&'life0 self,
session: SessionRecord,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Persist session, overwriting any record with the same session id.
Sourcefn load<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
) -> Pin<Box<dyn Future<Output = Result<SessionRecord>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
) -> Pin<Box<dyn Future<Output = Result<SessionRecord>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Load the record for session_id.
Returns StorageError::NotFound when no
record exists for the id.
Sourcefn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
session_id: &'life1 SessionId,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Delete the record for session_id.
Idempotent: deleting an absent session succeeds.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".