Struct comemo::Tracked

source ·
pub struct Tracked<'a, T, C = <T as Validate>::Constraint>where
    T: Track + ?Sized,{ /* private fields */ }
Expand description

Tracks accesses to a value.

Encapsulates a reference to a value and tracks all accesses to it. The only methods accessible on Tracked<T> are those defined in an implementation block or trait for T annotated with #[track]. For more details, see its documentation.

Variance

Typically you can ignore the defaulted C parameter. However, due to compiler limitations, this type will then be invariant over T. This limits how it can be used. In particular, invariance prevents you from creating a usable chain of tracked types.

struct Chain<'a> {
    outer: Tracked<'a, Self>,
    data: u32, // some data for the chain link
}

However, this is sometimes a useful pattern (for example, it allows you to detect cycles in memoized recursive algorithms). If you want to create a tracked chain or need covariance for another reason, you need to manually specify the constraint type like so:

struct Chain<'a> {
    outer: Tracked<'a, Self, <Chain<'static> as Validate>::Constraint>,
    data: u32, // some data for the chain link
}

Notice the 'static lifetime: This makes the compiler understand that no strange business that depends on 'a is happening in the associated constraint type. (In fact, all constraints are 'static.)

Trait Implementations§

source§

impl<'a, T> Clone for Tracked<'a, T>where T: Track + ?Sized,

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<T> Debug for Tracked<'_, T>where T: Track + ?Sized,

source§

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

Formats the value using the given formatter. Read more
source§

impl<'a, T> Deref for Tracked<'a, T>where T: Track + ?Sized,

§

type Target = <T as Surfaces>::Surface<'a>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'a, T> Copy for Tracked<'a, T>where T: Track + ?Sized,

Auto Trait Implementations§

§

impl<'a, T: ?Sized, C> RefUnwindSafe for Tracked<'a, T, C>where C: RefUnwindSafe, T: RefUnwindSafe,

§

impl<'a, T: ?Sized, C> Send for Tracked<'a, T, C>where C: Sync, T: Sync,

§

impl<'a, T: ?Sized, C> Sync for Tracked<'a, T, C>where C: Sync, T: Sync,

§

impl<'a, T: ?Sized, C> Unpin for Tracked<'a, T, C>

§

impl<'a, T: ?Sized, C> UnwindSafe for Tracked<'a, T, C>where C: RefUnwindSafe, T: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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 Twhere 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.