pub struct ManuallyStatic<T> { /* private fields */ }
Expand description
ManuallyStatic<T>
holds a value T
and provides references to it
with checking with debug_assertions
.
In debug builds, it tracks if the original ManuallyStatic
instance
has been dropped, causing any derived ManuallyStaticRef
or
ManuallyStaticRefMut
to panic upon dereference if the original
owner is no longer alive.
This is useful for simulating a ’static lifetime where you want runtime checks for use-after-free in debug environments.
Implementations§
Source§impl<T> ManuallyStatic<T>
impl<T> ManuallyStatic<T>
Sourcepub fn get_ref(&self) -> ManuallyStaticRef<T>
pub fn get_ref(&self) -> ManuallyStaticRef<T>
Returns a ManuallyStaticRef
that provides immutable access to the
contained value. In debug builds, dereferencing this will panic
if the original ManuallyStatic
instance has been dropped.
Sourcepub fn get_mut(&mut self) -> ManuallyStaticRefMut<T>
pub fn get_mut(&mut self) -> ManuallyStaticRefMut<T>
Returns a ManuallyStaticRefMut
that provides mutable access to the
contained value. In debug builds, dereferencing this will panic
if the original ManuallyStatic
instance has been dropped.
Trait Implementations§
Source§impl<T> Drop for ManuallyStatic<T>
Implements the Drop
trait for ManuallyStatic<T>
only in debug builds.
When ManuallyStatic
is dropped, it sets the was_dropped
flag to true
.
impl<T> Drop for ManuallyStatic<T>
Implements the Drop
trait for ManuallyStatic<T>
only in debug builds.
When ManuallyStatic
is dropped, it sets the was_dropped
flag to true
.