[][src]Struct ping_pong_cell::PingPongCell

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

An Atomic Cell game for up to two players.

Implementations

impl<T> PingPongCell<T>[src]

pub fn new(value: Option<T>) -> Self[src]

Create a new PingPongCell

pub fn take(&self) -> Option<T>[src]

If there is a value currently inside, take it.

pub fn put(&self, value: T)[src]

Replace the value inside unconditionally.

pub fn put_if_empty(&self, value: T) -> Result<(), T>[src]

Puts a value inside only if there is not one currently.

pub fn transact<F, R>(&self, fun: F) -> R where
    F: FnOnce(&mut Option<T>) -> R, 
[src]

Runs a closure with a mutable reference to the state

impl<T: Clone> PingPongCell<T>[src]

pub fn put_empty_clone(&self, value: T) -> Result<(), (T, T)>[src]

put_empty(), but clones the current contents on failure

pub fn clone_inner(&self) -> Option<T>[src]

Clones the contents, if any.

impl<T: Eq> PingPongCell<T>[src]

pub fn compare_and_swap(&self, expected: &T, new: T) -> Result<(), T>[src]

A single CAS operation

impl<T: Clone + Eq> PingPongCell<T>[src]

pub fn compare_swap_clone(
    &self,
    expected: &T,
    new: T
) -> Result<(), (T, Option<T>)>
[src]

A single CAS operation, cloning the current value on failure

Trait Implementations

impl<T: Debug> Debug for PingPongCell<T>[src]

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

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

Auto Trait Implementations

impl<T> Unpin for PingPongCell<T> where
    T: Unpin

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.