pub struct TokenStore { /* private fields */ }Expand description
Simple async in-memory token store (production should use Redis or database)
§Differences from previous implementation:
- Uses
tokio::sync::RwLockinstead ofstd::sync::RwLockfor async operations - Lock acquisition has timeout protection (default 500ms)
- Returns proper errors instead of panicking on lock failures
- All methods are now async
- Does not have poison mechanics (tokio
RwLockis panic-safe)
Implementations§
Source§impl TokenStore
impl TokenStore
Sourcepub async fn store_token(
&self,
key: String,
token: TokenInfo,
) -> TokenStoreResult<()>
pub async fn store_token( &self, key: String, token: TokenInfo, ) -> TokenStoreResult<()>
Store token in the store
§Errors
Returns TokenStoreError::LockTimeout if write lock cannot be acquired within timeout.
Sourcepub async fn get_token(&self, key: &str) -> TokenStoreResult<Option<TokenInfo>>
pub async fn get_token(&self, key: &str) -> TokenStoreResult<Option<TokenInfo>>
Get a token from the store
§Errors
Returns TokenStoreError::LockTimeout if read lock cannot be acquired within timeout.
Sourcepub async fn remove_token(&self, key: &str) -> TokenStoreResult<()>
pub async fn remove_token(&self, key: &str) -> TokenStoreResult<()>
Remove a token from the store
§Errors
Returns TokenStoreError::LockTimeout if write lock cannot be acquired within timeout.
Sourcepub async fn cleanup_expired(&self) -> TokenStoreResult<()>
pub async fn cleanup_expired(&self) -> TokenStoreResult<()>
Cleanup all expired tokens from the store
§Errors
Returns TokenStoreError::LockTimeout if write lock cannot be acquired within timeout.
Trait Implementations§
Source§impl Default for TokenStore
impl Default for TokenStore
Source§fn default() -> TokenStore
fn default() -> TokenStore
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !Freeze for TokenStore
impl !RefUnwindSafe for TokenStore
impl Send for TokenStore
impl Sync for TokenStore
impl Unpin for TokenStore
impl UnsafeUnpin for TokenStore
impl !UnwindSafe for TokenStore
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