pub struct MemoryStorage { /* private fields */ }Expand description
A simple in-memory storage implementation for testing and demonstration.
This implementation uses a HashMap wrapped in Arc<RwLock<>> for
thread-safe access. It doesn’t persist data across restarts and doesn’t
implement automatic expiration (expired entries are only removed during
cleanup operations).
§Thread Safety
This implementation is fully thread-safe and can handle concurrent operations from multiple threads.
§Usage
use nonce_auth::storage::{MemoryStorage, NonceStorage};
use std::time::Duration;
let storage = MemoryStorage::new();
// Store a nonce
storage.set("test-nonce", None, Duration::from_secs(300)).await?;
// Check if it exists
let exists = storage.exists("test-nonce", None).await?;
assert!(exists);Implementations§
Source§impl MemoryStorage
impl MemoryStorage
Trait Implementations§
Source§impl Debug for MemoryStorage
impl Debug for MemoryStorage
Source§impl Default for MemoryStorage
impl Default for MemoryStorage
Source§fn default() -> MemoryStorage
fn default() -> MemoryStorage
Returns the “default value” for a type. Read more
Source§impl NonceStorage for MemoryStorage
impl NonceStorage for MemoryStorage
Source§fn get<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
nonce: &'life1 str,
context: Option<&'life2 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<NonceEntry>, NonceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn get<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
nonce: &'life1 str,
context: Option<&'life2 str>,
) -> Pin<Box<dyn Future<Output = Result<Option<NonceEntry>, NonceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Retrieves a nonce entry if it exists. Read more
Source§fn set<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
nonce: &'life1 str,
context: Option<&'life2 str>,
_ttl: Duration,
) -> Pin<Box<dyn Future<Output = Result<(), NonceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn set<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
nonce: &'life1 str,
context: Option<&'life2 str>,
_ttl: Duration,
) -> Pin<Box<dyn Future<Output = Result<(), NonceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Stores a new nonce with expiration time. Read more
Source§fn exists<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
nonce: &'life1 str,
context: Option<&'life2 str>,
) -> Pin<Box<dyn Future<Output = Result<bool, NonceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn exists<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
nonce: &'life1 str,
context: Option<&'life2 str>,
) -> Pin<Box<dyn Future<Output = Result<bool, NonceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Checks if a nonce exists without retrieving it. Read more
Source§fn cleanup_expired<'life0, 'async_trait>(
&'life0 self,
cutoff_time: i64,
) -> Pin<Box<dyn Future<Output = Result<usize, NonceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn cleanup_expired<'life0, 'async_trait>(
&'life0 self,
cutoff_time: i64,
) -> Pin<Box<dyn Future<Output = Result<usize, NonceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Removes all expired nonces from storage. Read more
Auto Trait Implementations§
impl Freeze for MemoryStorage
impl !RefUnwindSafe for MemoryStorage
impl Send for MemoryStorage
impl Sync for MemoryStorage
impl Unpin for MemoryStorage
impl !UnwindSafe for MemoryStorage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more