pub trait SessionBackend: Send + Sync {
// Required methods
fn save(&self, session: &PersistedSession) -> Result<()>;
fn load(&self) -> Result<Option<PersistedSession>>;
fn delete(&self) -> Result<()>;
fn name(&self) -> &str;
// Provided methods
fn update_dc(&self, entry: &DcEntry) -> Result<()> { ... }
fn set_home_dc(&self, dc_id: i32) -> Result<()> { ... }
fn apply_update_state(&self, update: UpdateStateChange) -> Result<()> { ... }
fn cache_peer(&self, peer: &CachedPeer) -> Result<()> { ... }
}Expand description
Synchronous snapshot backend: saves and loads the full session at once.
All built-in backends implement this. Higher-level code should prefer the
extension methods below (update_dc, set_home_dc, update_state) which
avoid unnecessary full-snapshot writes.
Required Methods§
fn save(&self, session: &PersistedSession) -> Result<()>
fn load(&self) -> Result<Option<PersistedSession>>
fn delete(&self) -> Result<()>
Provided Methods§
Sourcefn update_dc(&self, entry: &DcEntry) -> Result<()>
fn update_dc(&self, entry: &DcEntry) -> Result<()>
Update a single DC entry without rewriting the entire session.
Typically called after:
- completing a DH handshake on a new DC (to persist its auth key)
- receiving updated DC addresses from
help.getConfig
Ported from Session::set_dc_option.
Sourcefn set_home_dc(&self, dc_id: i32) -> Result<()>
fn set_home_dc(&self, dc_id: i32) -> Result<()>
Change the home DC without touching any other session data.
Called after a successful *_MIGRATE redirect: the user’s account
now lives on a different DC.
Ported from Session::set_home_dc_id.
Sourcefn apply_update_state(&self, update: UpdateStateChange) -> Result<()>
fn apply_update_state(&self, update: UpdateStateChange) -> Result<()>
Apply a single update-sequence change without a full save/load.
Ported from Session::set_update_state(UpdateState).
update is the new partial or full state to merge in.
Sourcefn cache_peer(&self, peer: &CachedPeer) -> Result<()>
fn cache_peer(&self, peer: &CachedPeer) -> Result<()>
Cache a peer access hash without a full session save.
This is lossy-on-default (full round-trip) but correct.
Override in SQL backends to issue a single INSERT OR REPLACE.
Ported from Session::cache_peer.
Implementors§
impl SessionBackend for BinaryFileBackend
impl SessionBackend for InMemoryBackend
impl SessionBackend for SqliteBackend
sqlite-session only.