Struct cache::CacheHandle
source · pub struct CacheHandle<V>(/* private fields */);
Expand description
A handle to a cache entry that might still be generating.
Implementations§
source§impl<V: Any + Send + Sync> CacheHandle<V>
impl<V: Any + Send + Sync> CacheHandle<V>
sourcepub fn map<V2: Send + Sync + Any>(
&self,
map_fn: impl ValueMapFn<V, V2>
) -> CacheHandle<V2>
pub fn map<V2: Send + Sync + Any>( &self, map_fn: impl ValueMapFn<V, V2> ) -> CacheHandle<V2>
Maps an existing CacheHandle
to a CacheHandle
of a different type.
§Example
use std::sync::{Arc, Mutex};
use cache::{mem::TypeCache, error::Error, CacheableWithState};
let mut cache = TypeCache::new();
fn generate_fn(tuple: &(u64, u64)) -> u64 {
tuple.0 + tuple.1
}
let handle = cache.generate((5, 6), generate_fn);
assert_eq!(*handle.get(), 11);
// Does not call `generate_fn` again as the result has been cached.
let mapped_handle = handle.map(|res| res.map(|sum| *sum > 50));
assert_eq!(*mapped_handle.get(), false);
source§impl<V> CacheHandle<V>
impl<V> CacheHandle<V>
sourcepub fn try_get(&self) -> ArcResult<&V>
pub fn try_get(&self) -> ArcResult<&V>
Blocks on the cache entry, returning the result once it is ready.
Returns an error if one was returned by the generator.
source§impl<V: Debug> CacheHandle<V>
impl<V: Debug> CacheHandle<V>
source§impl<V, E> CacheHandle<Result<V, E>>
impl<V, E> CacheHandle<Result<V, E>>
sourcepub fn try_inner(&self) -> Result<&V, TryInnerError<'_, E>>
pub fn try_inner(&self) -> Result<&V, TryInnerError<'_, E>>
Blocks on the cache entry, returning the inner result.
Returns an error if the generator panicked or threw an error, or if the cache threw an error.
source§impl<V, E: Debug> CacheHandle<Result<V, E>>
impl<V, E: Debug> CacheHandle<Result<V, E>>
sourcepub fn unwrap_inner(&self) -> &V
pub fn unwrap_inner(&self) -> &V
Blocks on the cache entry, returning its output.
§Panics
Panics if the generator panicked or threw an error, or if an internal error was thrown by the cache.
source§impl<V: Debug, E> CacheHandle<Result<V, E>>
impl<V: Debug, E> CacheHandle<Result<V, E>>
sourcepub fn unwrap_err_inner(&self) -> &E
pub fn unwrap_err_inner(&self) -> &E
Blocks on the cache entry, returning the error returned by the generator.
§Panics
Panics if the generator panicked or an internal error was thrown by the cache. Also panics if the generator did not return an error.
Trait Implementations§
source§impl<V> Clone for CacheHandle<V>
impl<V> Clone for CacheHandle<V>
Auto Trait Implementations§
impl<V> !RefUnwindSafe for CacheHandle<V>
impl<V> Send for CacheHandle<V>
impl<V> Sync for CacheHandle<V>
impl<V> Unpin for CacheHandle<V>
impl<V> !UnwindSafe for CacheHandle<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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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