Skip to main content

SessionStore

Trait SessionStore 

Source
pub trait SessionStore: Send + Sync {
    // Required methods
    fn load<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 SessionId,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<Message>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn save<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        id: &'life1 SessionId,
        messages: &'life2 [Message],
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn list<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<SessionRecord>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn delete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id: &'life1 SessionId,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided method
    fn list_paginated<'life0, 'async_trait>(
        &'life0 self,
        opts: ListOptions,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<SessionRecord>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Trait implemented by every session-persistence backend.

Implementations must be cheap to share via Arc and safe to call concurrently from any async context.

Required Methods§

Source

fn load<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 SessionId, ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<Message>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Load a session’s full transcript. Returns Ok(None) when the id is not known — callers should treat this as “fresh session”.

Source

fn save<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 SessionId, messages: &'life2 [Message], ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Overwrite a session’s full transcript. Creating the session if it didn’t already exist.

Implementations should treat the provided slice as the authoritative state and persist it atomically — a crash mid-write must leave the store with either the old or new transcript, never a partial one.

Source

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

Enumerate every session the store knows about, newest-last. Returns metadata only — use Self::load to read message content.

Source

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

Remove a session. Deleting an unknown id is a no-op (not an error).

Provided Methods§

Source

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

Enumerate sessions with offset / limit pagination. The default implementation calls Self::list and slices in memory; backends that can push the window down to storage (e.g. SQLite LIMIT/OFFSET) should override this to avoid loading the full set.

Implementors§