[][src]Struct ping_pong_cell::PingPongCell

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

An Atomic Cell game for up to two players.


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, 

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(
    expected: &T,
    new: T
) -> Result<(), (T, Option<T>)>

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

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

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

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

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

The type returned in the event of a conversion error.