atomic_take

Struct AtomicTake

Source
pub struct AtomicTake<T> { /* private fields */ }
Expand description

A container with an atomic take operation.

Implementations§

Source§

impl<T> AtomicTake<T>

Source

pub const fn new(value: T) -> Self

Create a new AtomicTake with the given value.

Source

pub const fn empty() -> Self

Create an empty AtomicTake that contains no value.

Source

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

Takes out the value from this AtomicTake. It is guaranteed that exactly one caller will receive the value and all others will receive None.

Source

pub fn take_mut(&mut self) -> Option<T>

This methods does the same as take, but does not use an atomic swap.

This is safe because you cannot call this method without unique access to the AtomicTake, so no other threads will try to take it concurrently.

Source

pub fn is_taken(&self) -> bool

Check whether the value is taken. Note that if this returns false, then this is immediately stale if another thread could be concurrently trying to take it.

Source

pub fn insert(&mut self, value: T) -> Option<T>

Insert a new value into the AtomicTake and return the previous value.

This function requires unique access to ensure no other threads accesses the AtomicTake concurrently, as this operation cannot be performed atomically without a lock.

Trait Implementations§

Source§

impl<T> Debug for AtomicTake<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for AtomicTake<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> From<T> for AtomicTake<T>

Source§

fn from(t: T) -> AtomicTake<T>

Converts to this type from the input type.
Source§

impl<T: Send> Sync for AtomicTake<T>

Auto Trait Implementations§

§

impl<T> !Freeze for AtomicTake<T>

§

impl<T> !RefUnwindSafe for AtomicTake<T>

§

impl<T> Send for AtomicTake<T>
where T: Send,

§

impl<T> Unpin for AtomicTake<T>
where T: Unpin,

§

impl<T> UnwindSafe for AtomicTake<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.