sessions_core/
storage.rs

1use std::{future::Future, io::Result, time::Duration};
2
3use crate::Data;
4
5/// A Storage Trait
6pub trait Storage: Send + Sync {
7    /// Gets a [`Data`] from storage by the key
8    fn get(&self, key: &str) -> impl Future<Output = Result<Option<Data>>> + Send;
9
10    /// Sets a session [`Data`] into storage
11    fn set(&self, key: &str, val: Data, exp: &Duration) -> impl Future<Output = Result<()>> + Send;
12
13    /// Removes a data from storage by the key
14    fn remove(&self, key: &str) -> impl Future<Output = Result<()>> + Send;
15
16    /// Resets the storage and remove all keys
17    fn reset(&self) -> impl Future<Output = Result<()>> + Send {
18        async { Ok(()) }
19    }
20
21    /// Closes the connection
22    fn close(&self) -> impl Future<Output = Result<()>> + Send {
23        async { Ok(()) }
24    }
25}