Skip to main content

SessionStore

Trait SessionStore 

Source
pub trait SessionStore: Send + Sync {
    // Required methods
    fn save(
        &self,
        asset: &SessionAsset,
    ) -> impl Future<Output = Result<(), StorageError>> + Send;
    fn load(
        &self,
        id: &str,
    ) -> impl Future<Output = Result<SessionAsset, StorageError>> + Send;
    fn list(
        &self,
    ) -> impl Future<Output = Result<Vec<SessionMeta>, StorageError>> + Send;
    fn delete(
        &self,
        id: &str,
    ) -> impl Future<Output = Result<(), StorageError>> + Send;
    fn exists(
        &self,
        id: &str,
    ) -> impl Future<Output = Result<bool, StorageError>> + Send;

    // Provided method
    fn sync_status(&self) -> SyncStatus { ... }
}
Expand description

Session storage abstraction.

Implementations must be thread-safe (Send + Sync) for use across async tasks.

§Design Principles

  • Async: All operations are async for I/O efficiency
  • Error Handling: Returns StorageError for consistent error handling
  • Metadata Efficiency: list() returns lightweight metadata, not full assets

§Example

use orcs_runtime::session::{SessionStore, SessionAsset, StorageError};

async fn save_session(store: &impl SessionStore, asset: &SessionAsset) -> Result<(), StorageError> {
    store.save(asset).await?;
    println!("Saved session: {}", asset.id);
    Ok(())
}

Required Methods§

Source

fn save( &self, asset: &SessionAsset, ) -> impl Future<Output = Result<(), StorageError>> + Send

Saves a session asset.

If a session with the same ID exists, it will be overwritten.

Source

fn load( &self, id: &str, ) -> impl Future<Output = Result<SessionAsset, StorageError>> + Send

Loads a session asset by ID.

§Errors

Returns StorageError::NotFound if the session does not exist.

Source

fn list( &self, ) -> impl Future<Output = Result<Vec<SessionMeta>, StorageError>> + Send

Lists all session metadata.

Returns lightweight metadata for each session, sorted by updated_at descending.

Source

fn delete( &self, id: &str, ) -> impl Future<Output = Result<(), StorageError>> + Send

Deletes a session by ID.

§Errors

Returns StorageError::NotFound if the session does not exist.

Source

fn exists( &self, id: &str, ) -> impl Future<Output = Result<bool, StorageError>> + Send

Checks if a session exists.

Provided Methods§

Source

fn sync_status(&self) -> SyncStatus

Returns the current sync status.

For local-only stores, this returns SyncStatus::offline().

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§