pub trait SessionStore: Send + Sync {
// Required methods
fn read(&self, session_id: &str) -> Option<HashMap<String, Value>>;
fn write(&self, session_id: &str, data: HashMap<String, Value>);
fn destroy(&self, session_id: &str);
// Provided method
fn exists(&self, session_id: &str) -> bool { ... }
}Expand description
Session 存储后端 trait
抽象会话数据的持久化层,对齐 PHP think\session\Driver 抽象类。
实现方需提供基于 session_id 的命名空间隔离。
§PHP 对齐
abstract class Driver implements SessionHandlerInterface {
// read($sessionId): string
// write($sessionId, $data): bool
// destroy($sessionId): bool
// gc($maxLifetime): int
}Required Methods§
Sourcefn read(&self, session_id: &str) -> Option<HashMap<String, Value>>
fn read(&self, session_id: &str) -> Option<HashMap<String, Value>>
读取指定 session_id 的所有数据
返回 None 表示 session 不存在或已过期。
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".