pub struct OnceMap<K, V> { /* private fields */ }Expand description
A process-lifetime cache that maps K → V and computes each entry on
first access. See module docs for semantics.
Implementations§
Source§impl<K: Eq + Hash + Clone, V: Clone> OnceMap<K, V>
impl<K: Eq + Hash + Clone, V: Clone> OnceMap<K, V>
Sourcepub fn get_or_init_with<F>(&self, key: &K, init: F) -> Vwhere
F: FnOnce() -> V,
pub fn get_or_init_with<F>(&self, key: &K, init: F) -> Vwhere
F: FnOnce() -> V,
Return the value for key, computing and caching it with init
on first access. The lock is held across init, so concurrent
callers for the same key serialize.
Sourcepub async fn get_or_init_async<F, Fut>(&self, key: &K, init: F) -> V
pub async fn get_or_init_async<F, Fut>(&self, key: &K, init: F) -> V
Async variant of Self::get_or_init_with. The lock is released
across the await, so different keys don’t serialize. Two callers
for the same key may both run init; the last write wins.
Sourcepub fn get(&self, key: &K) -> Option<V>
pub fn get(&self, key: &K) -> Option<V>
Read without computing. Returns None if the key was never inserted.
Trait Implementations§
Auto Trait Implementations§
impl<K, V> !Freeze for OnceMap<K, V>
impl<K, V> RefUnwindSafe for OnceMap<K, V>
impl<K, V> Send for OnceMap<K, V>
impl<K, V> Sync for OnceMap<K, V>
impl<K, V> Unpin for OnceMap<K, V>
impl<K, V> UnsafeUnpin for OnceMap<K, V>
impl<K, V> UnwindSafe for OnceMap<K, V>
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> 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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request