Struct s2n_quic_core::memo::Memo

source ·
pub struct Memo<T: Copy, Input, Check = DefaultConsistencyCheck> { /* private fields */ }
Expand description

A datastructure that memoizes a query function

This can be used for when queries rarely change and can potentially be expensive or on hot code paths. After the input is mutated, the query value should be cleared to signal that the function needs to be executed again.

In debug mode the get call will always run the query and assert that the values match.

Implementations§

source§

impl<T: Copy + PartialEq + Debug, Input, Check: ConsistencyCheck> Memo<T, Input, Check>

source

pub fn new(query: fn(_: &Input) -> T) -> Self

Creates a new Memo over a query function

source

pub fn get(&self, input: &Input) -> T

Returns the current value of the query function, which may be cached

source

pub fn clear(&self)

Clears the cached value of the query function

source

pub fn check_consistency(&self, input: &Input)

Asserts that the cached value reflects the current query result in debug mode

Trait Implementations§

source§

impl<T: Clone + Copy, Input: Clone, Check: Clone> Clone for Memo<T, Input, Check>

source§

fn clone(&self) -> Memo<T, Input, Check>

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<T: Copy + Debug, Input, Check> Debug for Memo<T, Input, Check>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, Input, Check = ConsistencyCheckAlways> !Freeze for Memo<T, Input, Check>

§

impl<T, Input, Check = ConsistencyCheckAlways> !RefUnwindSafe for Memo<T, Input, Check>

§

impl<T, Input, Check> Send for Memo<T, Input, Check>
where Check: Send, T: Send,

§

impl<T, Input, Check = ConsistencyCheckAlways> !Sync for Memo<T, Input, Check>

§

impl<T, Input, Check> Unpin for Memo<T, Input, Check>
where Check: Unpin, T: Unpin,

§

impl<T, Input, Check> UnwindSafe for Memo<T, Input, Check>
where Check: UnwindSafe, T: UnwindSafe,

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.

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> 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.
source§

impl<T, U> Upcast<T> for U
where T: UpcastFrom<U>,

source§

fn upcast(self) -> T

source§

impl<T, B> UpcastFrom<Counter<T, B>> for T

source§

fn upcast_from(value: Counter<T, B>) -> T