[−][src]Struct atomicbox_nostd::AtomicOptionBox
A type that holds a single Option<Box<T>>
value and can be safely shared
between threads.
Implementations
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 take(&self, order: Ordering) -> Option<Box<T>>
[src]
Atomically set this AtomicOptionBox
to None
and return the
previous value.
This does not allocate or free memory, and it neither clones nor drops
any values. It is equivalent to calling self.swap(None, order)
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(Some(Box::new("ok"))); let prev_value = atom.take(Ordering::AcqRel); assert!(prev_value.is_some()); let prev_value = atom.take(Ordering::AcqRel); assert!(prev_value.is_none());
pub fn swap_mut(&self, other: &mut Option<Box<T>>, order: Ordering)
[src]
Atomically swaps the contents of this AtomicOptionBox
with the contents of other
.
This does not allocate or free memory, and it neither clones nor drops
any values. The pointers in *other
and self
are simply exchanged.
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 mut boxed = Some(Box::new("ok")); let prev_value = atom.swap_mut(&mut boxed, Ordering::AcqRel); assert_eq!(boxed, 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> Debug for AtomicOptionBox<T>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
The {:?}
format of an AtomicOptionBox<T>
looks like
"AtomicOptionBox(0x12341234)"
or "AtomicOptionBox(None)"
.
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: Send> Send for AtomicOptionBox<T>
[src]
impl<T: Sync> Sync for AtomicOptionBox<T>
[src]
Auto Trait Implementations
impl<T> Unpin for AtomicOptionBox<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
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, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,