seance/backend/
mod.rs

1use std::{error::Error, future::Future};
2
3/// Filesystem backend
4#[cfg_attr(nightly, doc(cfg(feature = "fs-backend")))]
5#[cfg(feature = "fs-backend")]
6pub mod fs;
7
8/// Redis backend
9#[cfg_attr(nightly, doc(cfg(feature = "redis-backend")))]
10#[cfg(feature = "redis-backend")]
11pub mod redis;
12
13/// A session backend interface
14pub trait SessionBackend {
15    /// An error occurred in backend
16    type Error: Error + Send + Sync + 'static;
17
18    /// Returns a list of available session IDs
19    fn get_sessions(&mut self) -> impl Future<Output = Result<Vec<String>, Self::Error>> + Send;
20
21    /// Returns the time when session was created in seconds
22    ///
23    /// This method MUST return session age if session exists and None otherwise
24    ///
25    /// # Arguments
26    ///
27    /// * session_id - ID of a session
28    fn get_session_age(&mut self, session_id: &str) -> impl Future<Output = Result<Option<u64>, Self::Error>> + Send;
29
30    /// Removes a session
31    ///
32    /// # Arguments
33    ///
34    /// * session_id - ID of a session
35    fn remove_session(&mut self, session_id: &str) -> impl Future<Output = Result<(), Self::Error>> + Send;
36
37    /// Read a value from store
38    ///
39    /// * session_id - ID of a session
40    /// * key - Key to read value from
41    fn read_value(
42        &mut self,
43        session_id: &str,
44        key: &str,
45    ) -> impl Future<Output = Result<Option<Vec<u8>>, Self::Error>> + Send;
46
47    /// Write a value to store
48    ///
49    /// # Arguments
50    ///
51    /// * session_id - ID of a session
52    /// * key - Key to write value to
53    /// * value - Value to write
54    fn write_value(
55        &mut self,
56        session_id: &str,
57        key: &str,
58        value: &[u8],
59    ) -> impl Future<Output = Result<(), Self::Error>> + Send;
60
61    /// Remove a value from store
62    ///
63    /// * session_id - ID of a session
64    /// * key - Key to read value from
65    fn remove_value(&mut self, session_id: &str, key: &str) -> impl Future<Output = Result<(), Self::Error>> + Send;
66}