serenade_session/store.rs
1//! Session persistence contract.
2
3use std::collections::HashMap;
4
5use crate::SessionError;
6
7/// Loads and saves session attribute maps by id.
8pub trait SessionStore: Send + Sync {
9 /// Returns stored attributes for `id`, or `None` when unknown.
10 ///
11 /// # Errors
12 ///
13 /// Returns [`SessionError`] when the backend fails.
14 fn load(&self, id: &str) -> Result<Option<HashMap<String, String>>, SessionError>;
15
16 /// Persists `attributes` for `id`.
17 ///
18 /// # Errors
19 ///
20 /// Returns [`SessionError`] when the backend fails.
21 fn save(&self, id: &str, attributes: &HashMap<String, String>) -> Result<(), SessionError>;
22
23 /// Deletes `id` when present.
24 ///
25 /// # Errors
26 ///
27 /// Returns [`SessionError`] when the backend fails.
28 fn delete(&self, id: &str) -> Result<(), SessionError>;
29}