[][src]Struct atomicbox_nostd::AtomicBox

pub struct AtomicBox<T> { /* fields omitted */ }

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]

fn default() -> AtomicBox<T>[src]

The default AtomicBox<T> value boxes the default T value.

impl<T> Drop for AtomicBox<T>[src]

fn drop(&mut self)[src]

Dropping an AtomicBox<T> drops the final Box<T> value stored in it.

impl<T: Send> Send for AtomicBox<T>[src]

impl<T: Sync> Sync for AtomicBox<T>[src]

Auto Trait Implementations

impl<T> Unpin for AtomicBox<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.