pub struct MemoryTokenStore { /* private fields */ }Expand description
In-memory token store backed by an Arc<RwLock<HashMap>>.
Designed for multi-user scenarios (e.g., TMU — Trustee Multi-User) where
each user gets an isolated token store that lives in process memory and
is lost on restart. Because it uses Arc<RwLock<...>> internally, cloning
a MemoryTokenStore creates another handle to the same underlying map
— so it can be shared across async tasks and passed by clone.
§Use Cases
- Per-user token isolation: Each user session gets its own
MemoryTokenStoreinstance. Tokens for one user are invisible to another, unlikeFileTokenStorewhere all tokens share~/.{agent_name}/tokens/. - Testing: No filesystem cleanup needed; tokens vanish on drop.
- Short-lived processes: No persistence needed.
§Example
use pep::token_store::{TokenStore, MemoryTokenStore, StoredToken};
let store = MemoryTokenStore::new();
let token = StoredToken::new("access123", Some("refresh456".to_string()),
"Bearer", "2099-01-01T00:00:00Z", None);
store.save("my-mcp-server", &token).unwrap();
let loaded = store.load("my-mcp-server").unwrap().unwrap();
assert_eq!(loaded.access_token, "access123");§Clone Semantics
Cloning a MemoryTokenStore does not copy the data — it creates
another reference to the same shared map:
use pep::token_store::{TokenStore, MemoryTokenStore, StoredToken};
let store_a = MemoryTokenStore::new();
let store_b = store_a.clone(); // shares the same underlying map
store_a.save("key", &StoredToken::new("tok", None, "Bearer", "2099-01-01T00:00:00Z", None)).unwrap();
assert!(store_b.load("key").unwrap().is_some()); // visible from cloneImplementations§
Trait Implementations§
Source§impl Clone for MemoryTokenStore
impl Clone for MemoryTokenStore
Source§fn clone(&self) -> MemoryTokenStore
fn clone(&self) -> MemoryTokenStore
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MemoryTokenStore
impl Debug for MemoryTokenStore
Source§impl Default for MemoryTokenStore
impl Default for MemoryTokenStore
Source§fn default() -> MemoryTokenStore
fn default() -> MemoryTokenStore
Returns the “default value” for a type. Read more
Source§impl TokenStore for MemoryTokenStore
impl TokenStore for MemoryTokenStore
Auto Trait Implementations§
impl Freeze for MemoryTokenStore
impl RefUnwindSafe for MemoryTokenStore
impl Send for MemoryTokenStore
impl Sync for MemoryTokenStore
impl Unpin for MemoryTokenStore
impl UnsafeUnpin for MemoryTokenStore
impl UnwindSafe for MemoryTokenStore
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more