[−][src]Struct atomicbox_nostd::AtomicBox
A type that holds a single Box<T>
value and can be safely shared between
threads.
Implementations
impl<T> AtomicBox<T>
[src]
pub fn new(value: Box<T>) -> AtomicBox<T>
[src]
Creates a new AtomicBox
with the given value.
Examples
use atomicbox::AtomicBox; let atomic_box = AtomicBox::new(Box::new(0));
pub fn swap(&self, other: Box<T>, order: Ordering) -> Box<T>
[src]
Atomically set this AtomicBox
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::AtomicBox; let atom = AtomicBox::new(Box::new("one")); let prev_value = atom.swap(Box::new("two"), Ordering::AcqRel); assert_eq!(*prev_value, "one");
pub fn swap_mut(&self, other: &mut Box<T>, order: Ordering)
[src]
Atomically swaps the contents of this AtomicBox
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::AtomicBox; let atom = AtomicBox::new(Box::new("one")); let mut boxed = Box::new("two"); atom.swap_mut(&mut boxed, Ordering::AcqRel); assert_eq!(*boxed, "one");
pub fn into_inner(self) -> Box<T>
[src]
Consume this AtomicBox
, returning the last box value it contained.
Examples
use atomicbox::AtomicBox; let atom = AtomicBox::new(Box::new("hello")); assert_eq!(atom.into_inner(), Box::new("hello"));
pub fn get_mut(&mut self) -> &mut T
[src]
Returns a mutable reference to the contained value.
This is safe because it borrows the AtomicBox
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 AtomicBox<T>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
The {:?}
format of an AtomicBox<T>
looks like "AtomicBox(0x12341234)"
.
impl<T> Default for AtomicBox<T> where
Box<T>: Default,
[src]
Box<T>: Default,
impl<T> Drop for AtomicBox<T>
[src]
impl<T: Send> Send for AtomicBox<T>
[src]
impl<T: Sync> Sync for AtomicBox<T>
[src]
Auto Trait Implementations
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>,