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>

source

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>

source

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

pub fn poll(&self) -> Option<ArcResult<&V>>

Checks whether the underlying entry is ready.

Returns the entry if available, otherwise returns None.

source

pub fn get(&self) -> &V

Blocks on the cache entry, returning its output.

§Panics

Panics if the generator failed to run or an internal error was thrown by the cache.

source§

impl<V: Debug> CacheHandle<V>

source

pub fn get_err(&self) -> Arc<Error>

Blocks on the cache entry, returning the error thrown by the cache.

§Panics

Panics if no error was thrown by the cache.

source§

impl<V, E> CacheHandle<Result<V, E>>

source

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>>

source

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>>

source

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>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<V> Debug for CacheHandle<V>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more