rocket_sessions/
lib.rs

1#![warn(clippy::all)]
2#![doc = include_str!("../README.md")]
3#[macro_use]
4extern crate async_trait;
5
6use std::fmt::{Debug, Display};
7use std::time::Duration;
8
9#[cfg(feature = "redis")]
10mod redis;
11
12#[cfg(feature = "in-memory")]
13pub mod in_memory;
14
15/// Represents a handle to the underlying data structure
16/// managing sessions in a Rocket application.
17/// The `id` parameter corresponds to the session token
18/// stored by the client. This should correspond to a
19/// random alphanumeric string of letters with sufficient entropy.
20///
21/// The `key` and `value` parameters can be used to set custom fields. They could
22/// be used to store CRSF tokens, timestamps or some other session metadata.
23#[async_trait]
24pub trait SessionManager {
25    type Error: Debug + Display;
26    async fn set(&self, id: &str, key: &str, val: &str, time: Duration) -> Result<(), Self::Error>;
27    async fn get(&self, id: &str, key: &str) -> Result<Option<String>, Self::Error>;
28    async fn delete(&self, id: &str, key: &str) -> Result<(), Self::Error>;
29    async fn expire_in(&self, id: &str, key: &str, time: Duration) -> Result<(), Self::Error>;
30    async fn clear_all(&self) -> Result<(), Self::Error>;
31}