pub struct MonoBox<T> { /* private fields */ }Expand description
A MonoBox<T> is an atomic, lock-free, write-once
Option<Box<T>>. Write-once means that a MonoBox can only
transition from None to Some<Box<T>> once, and is then
frozen in that state until destruction.
As a special case, when one has exclusive ownership over the
MonoBox (evidenced by a &mut reference), it is possible to
MonoBox::swap its contents with an arbitrary
Option<Box<T>>. This non-monotonic operation is safe because
the mutable references guarantees no other thread can observe the
transition.
Implementations§
Source§impl<T> MonoBox<T>
impl<T> MonoBox<T>
Sourcepub fn new(inner: Option<Box<T>>) -> Self
pub fn new(inner: Option<Box<T>>) -> Self
Returns a fresh MonoBox that holds inner.
Use Default::default() or MonoBox::empty() for a
None initial value.
Sourcepub fn swap(&mut self, value: Option<Box<T>>) -> Option<Box<T>>
pub fn swap(&mut self, value: Option<Box<T>>) -> Option<Box<T>>
Returns the value previously stored in this MonoBox and
replaces it with value.
Sourcepub fn store_value(&self, value: T) -> bool
pub fn store_value(&self, value: T) -> bool
Sourcepub fn into_inner(self) -> Option<Box<T>>
pub fn into_inner(self) -> Option<Box<T>>
Consumes this MonoBox, returning the wrapped value, if
any.