Skip to main content

SessionManagerTrait

Trait SessionManagerTrait 

Source
pub trait SessionManagerTrait: Send + Sync {
Show 13 methods // Required methods fn create<'life0, 'async_trait>( &'life0 self, config: SessionConfig, ) -> Pin<Box<dyn Future<Output = Layer2Result<SessionId>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 SessionId, ) -> Pin<Box<dyn Future<Output = Layer2Result<Option<Session>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_or_create<'life0, 'life1, 'async_trait>( &'life0 self, id: Option<&'life1 SessionId>, config: SessionConfig, ) -> Pin<Box<dyn Future<Output = Layer2Result<SessionId>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn save<'life0, 'life1, 'async_trait>( &'life0 self, session: &'life1 Session, ) -> Pin<Box<dyn Future<Output = Layer2Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn delete<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 SessionId, ) -> Pin<Box<dyn Future<Output = Layer2Result<bool>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn list<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Layer2Result<Vec<SessionMeta>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn update<'life0, 'life1, 'async_trait, F>( &'life0 self, id: &'life1 SessionId, update_fn: F, ) -> Pin<Box<dyn Future<Output = Layer2Result<bool>> + Send + 'async_trait>> where F: FnOnce(&mut Session) + Send + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn read<'life0, 'life1, 'async_trait, F, T>( &'life0 self, id: &'life1 SessionId, read_fn: F, ) -> Pin<Box<dyn Future<Output = Layer2Result<Option<T>>> + Send + 'async_trait>> where F: FnOnce(&Session) -> T + Send + 'async_trait, T: Send + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_state<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 SessionId, ) -> Pin<Box<dyn Future<Output = Layer2Result<Option<AgentState>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn set_state<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 SessionId, state: AgentState, ) -> Pin<Box<dyn Future<Output = Layer2Result<bool>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn add_message<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 SessionId, message: Message, ) -> Pin<Box<dyn Future<Output = Layer2Result<bool>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_messages<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 SessionId, ) -> Pin<Box<dyn Future<Output = Layer2Result<Option<Vec<Message>>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn stats(&self) -> SessionStats;
}
Expand description

会话管理器接口

定义会话生命周期的核心操作。

Required Methods§

Source

fn create<'life0, 'async_trait>( &'life0 self, config: SessionConfig, ) -> Pin<Box<dyn Future<Output = Layer2Result<SessionId>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

创建新会话

§Arguments
  • config - 会话配置
§Returns

新创建的会话 ID

Source

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

获取会话

§Arguments
  • id - 会话 ID
§Returns

会话对象(只读)

Source

fn get_or_create<'life0, 'life1, 'async_trait>( &'life0 self, id: Option<&'life1 SessionId>, config: SessionConfig, ) -> Pin<Box<dyn Future<Output = Layer2Result<SessionId>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

获取或创建会话

如果会话存在则返回,否则创建新会话。

§Arguments
  • id - 会话 ID(可选)
  • config - 创建新会话时的配置
Source

fn save<'life0, 'life1, 'async_trait>( &'life0 self, session: &'life1 Session, ) -> Pin<Box<dyn Future<Output = Layer2Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

保存会话状态

§Arguments
  • session - 会话对象
Source

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

删除会话

§Arguments
  • id - 会话 ID
Source

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

列出所有会话

§Returns

会话元数据列表

Source

fn update<'life0, 'life1, 'async_trait, F>( &'life0 self, id: &'life1 SessionId, update_fn: F, ) -> Pin<Box<dyn Future<Output = Layer2Result<bool>> + Send + 'async_trait>>
where F: FnOnce(&mut Session) + Send + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

更新会话状态(带写锁)

§Arguments
  • id - 会话 ID
  • update_fn - 更新函数
Source

fn read<'life0, 'life1, 'async_trait, F, T>( &'life0 self, id: &'life1 SessionId, read_fn: F, ) -> Pin<Box<dyn Future<Output = Layer2Result<Option<T>>> + Send + 'async_trait>>
where F: FnOnce(&Session) -> T + Send + 'async_trait, T: Send + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

读取会话状态(带读锁)

§Arguments
  • id - 会话 ID
  • read_fn - 读取函数
Source

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

获取会话状态

Source

fn set_state<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 SessionId, state: AgentState, ) -> Pin<Box<dyn Future<Output = Layer2Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

设置会话状态

Source

fn add_message<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 SessionId, message: Message, ) -> Pin<Box<dyn Future<Output = Layer2Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

添加消息到会话

Source

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

获取会话消息列表

Source

fn stats(&self) -> SessionStats

获取统计信息

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§