pub struct Tracked<'a, T, C = <T as Track>::Call>{ /* 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 call type like so:
struct Chain<'a> {
outer: Tracked<'a, Self, <Chain<'static> as Track>::Call>,
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§
impl<'a, T> Copy for Tracked<'a, T>
Auto Trait Implementations§
impl<'a, T, C> Freeze for Tracked<'a, T, C>where
T: ?Sized,
impl<'a, T, C = <T as Track>::Call> !RefUnwindSafe for Tracked<'a, T, C>
impl<'a, T, C> Send for Tracked<'a, T, C>
impl<'a, T, C> Sync for Tracked<'a, T, C>
impl<'a, T, C> Unpin for Tracked<'a, T, C>where
T: ?Sized,
impl<'a, T, C = <T as Track>::Call> !UnwindSafe for Tracked<'a, T, C>
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)