pub struct TrackedVariable<T: Trackable> { /* private fields */ }
Expand description
A wrapper that provides automatic lifecycle tracking for variables.
This struct wraps any Trackable
type and automatically handles:
- Creation tracking when constructed
- Destruction tracking when dropped with duplicate protection
- Transparent access to the wrapped value via Deref/DerefMut
- Smart pointer detection and specialized handling for Rc, Arc, and Box
- Thread-safe drop protection using atomic flags
- Panic-safe error handling in drop logic
§Key Features:
- Drop Protection: Prevents duplicate destruction tracking
- Smart Pointer Support: Automatic detection and handling of reference-counted types
- Error Resilience: Robust error handling that won’t crash on tracking failures
- Thread Safety: Uses atomic operations for safe concurrent access
- Zero-Cost Abstraction: Transparent access to wrapped value with minimal overhead
Implementations§
Source§impl<T: Trackable> TrackedVariable<T>
impl<T: Trackable> TrackedVariable<T>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consume the wrapper and return the inner value.
This method safely extracts the wrapped value while ensuring that destruction tracking occurs exactly once. It uses atomic protection to prevent duplicate tracking even if the Drop trait would normally execute afterwards.
§Safety Features:
- Uses
ManuallyDrop
to prevent automatic Drop execution - Atomic flag prevents duplicate destruction tracking
- Proper error handling for tracking failures
- Smart pointer detection for specialized handling
Trait Implementations§
Source§impl<T: Trackable> Deref for TrackedVariable<T>
impl<T: Trackable> Deref for TrackedVariable<T>
Source§impl<T: Trackable> DerefMut for TrackedVariable<T>
impl<T: Trackable> DerefMut for TrackedVariable<T>
Auto Trait Implementations§
impl<T> !Freeze for TrackedVariable<T>
impl<T> RefUnwindSafe for TrackedVariable<T>where
T: RefUnwindSafe,
impl<T> Send for TrackedVariable<T>where
T: Send,
impl<T> Sync for TrackedVariable<T>where
T: Sync,
impl<T> Unpin for TrackedVariable<T>where
T: Unpin,
impl<T> UnwindSafe for TrackedVariable<T>where
T: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more