[−][src]Struct atomicbox::AtomicOptionBox
A type that holds a single Option<Box<T>>
value and can be safely shared
between threads.
Methods
impl<T> AtomicOptionBox<T>
[src]
pub fn new(value: Option<Box<T>>) -> AtomicOptionBox<T>
[src]
Creates a new AtomicOptionBox
with the given value.
Examples
use atomicbox::AtomicOptionBox; let atomic_box = AtomicOptionBox::new(Some(Box::new(0)));
pub fn swap(&self, other: Option<Box<T>>, order: Ordering) -> Option<Box<T>>
[src]
Atomically set this AtomicOptionBox
to other
and return the
previous value.
This does not allocate or free memory, and it neither clones nor drops
any values. other
is moved into self
; the value previously in
self
is returned.
ordering
must be either Ordering::AcqRel
or Ordering::SeqCst
,
as other values would not be safe if T
contains any data.
Panics
Panics if ordering
is not one of the two allowed values.
Examples
use std::sync::atomic::Ordering; use atomicbox::AtomicOptionBox; let atom = AtomicOptionBox::new(None); let prev_value = atom.swap(Some(Box::new("ok")), Ordering::AcqRel); assert_eq!(prev_value, None);
pub fn into_inner(self) -> Option<Box<T>>
[src]
Consume this AtomicOptionBox
, returning the last option value it
contained.
Examples
use atomicbox::AtomicOptionBox; let atom = AtomicOptionBox::new(Some(Box::new("hello"))); assert_eq!(atom.into_inner(), Some(Box::new("hello")));
pub fn get_mut(&mut self) -> Option<&mut T>
[src]
Returns a mutable reference to the contained value.
This is safe because it borrows the AtomicOptionBox
mutably, which
ensures that no other threads can concurrently access either the atomic
pointer field or the boxed data it points to.
Trait Implementations
impl<T> Default for AtomicOptionBox<T>
[src]
fn default() -> AtomicOptionBox<T>
[src]
The default AtomicOptionBox<T>
value is AtomicBox::new(None)
.
impl<T> Drop for AtomicOptionBox<T>
[src]
fn drop(&mut self)
[src]
Dropping an AtomicOptionBox<T>
drops the final Box<T>
value (if
any) stored in it.
impl<T> Debug for AtomicOptionBox<T>
[src]
Auto Trait Implementations
impl<T> Send for AtomicOptionBox<T>
impl<T> Sync for AtomicOptionBox<T>
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,