author_web/session/store/
mod.rs1use crate::session::SessionKey;
2use async_trait::async_trait;
3use std::borrow::Borrow;
4use std::hash::Hash;
5
6#[cfg(feature = "in-memory")]
7pub mod in_memory;
8
9#[async_trait]
10pub trait SessionStore: Send {
11 type Session;
12 type Key: SessionKey;
13
14 async fn create_session(&self) -> anyhow::Result<(Self::Key, Self::Session)>;
15 async fn load_session(&self, key: &Self::Key) -> anyhow::Result<Option<Self::Session>>;
16}
17
18#[async_trait]
19pub trait SessionDataValueStorage<K, V>
20where
21 K: Hash + Eq,
22{
23 async fn set_value<KVal, VVal>(&self, key: KVal, val: VVal) -> anyhow::Result<()>
24 where
25 KVal: Into<K> + Send,
26 VVal: Into<V> + Send;
27
28 async fn unset_value<KVal>(&self, key: KVal) -> anyhow::Result<()>
29 where
30 KVal: Into<K> + Send;
31
32 async fn get_value<KRef>(&self, key: &KRef) -> anyhow::Result<Option<V>>
33 where
34 KRef: Hash + Eq + ?Sized + ToOwned<Owned = K> + Sync,
35 K: Borrow<KRef> + Hash + Eq;
36}