Struct ref_swap::OptionRefSwap

source ·
pub struct OptionRefSwap<'a, T> { /* private fields */ }
Expand description

An optionnal reference that can atomically be changed to another optionnal reference with the same lifetime and type

Implementations§

source§

impl<'a, T> OptionRefSwap<'a, T>

source

pub const fn new(data: Option<&'a T>) -> Self

source

pub fn compare_and_swap( &self, current: Option<&'a T>, new: Option<&'a T>, order: Ordering ) -> Option<&'a T>

👎Deprecated: Use compare_exchange or compare_exchange_weak instead

Stores a reference if the current value is the same as the current value.

Be aware that the comparison is only between the reference, not between the value. If current point to another adress in memory than the reference currently holds, it will fail, Even if both are equal according to a PartialEq implementation.

For more information on the orderings, se the documentation of AtomicPtr::compare_and_swap

source

pub fn compare_exchange( &self, current: Option<&'a T>, new: Option<&'a T>, success: Ordering, failure: Ordering ) -> Result<Option<&'a T>, Option<&'a T>>

Stores a reference if the current value is the same as the current value.

Be aware that the comparison is only between the reference, not between the value. If current point to another adress in memory than the reference currently holds, it will fail, Even if both are equal according to a PartialEq implementation.

For more information on the orderings, se the documentation of AtomicPtr::compare_exchange

source

pub fn compare_exchange_weak( &self, current: Option<&'a T>, new: Option<&'a T>, success: Ordering, failure: Ordering ) -> Result<Option<&'a T>, Option<&'a T>>

Stores a reference if the current value is the same as the current value.

Be aware that the comparison is only between the reference, not between the value. If current point to another adress in memory than the reference currently holds, it will fail, Even if both are equal according to a PartialEq implementation.

For more information on the orderings, se the documentation of AtomicPtr::compare_exchange_weak

source

pub fn into_inner(self) -> &'a T

Consumes the atomic and returns the contained value.

This is safe because passing self by value guarantees that no other threads are concurrently accessing the atomic data.

source

pub fn fetch_update<F: FnMut(Option<&'a T>) -> Option<Option<&'a T>>>( &self, set_order: Ordering, fetch_order: Ordering, f: F ) -> Result<Option<&'a T>, Option<&'a T>>

Fetches the value, and applies a function to it that returns an optional new value. Returns a Result of Ok(previous_value) if the function returned Some(_), else Err(previous_value).

For more information on the orderings, se the documentation of AtomicPtr::fetch_update

source

pub fn load(&self, order: Ordering) -> Option<&'a T>

Loads a value

source

pub fn store(&self, ptr: Option<&'a T>, order: Ordering)

Stores a value

source

pub fn swap(&self, ptr: Option<&'a T>, order: Ordering) -> Option<&'a T>

Stores a value into the pointer, returning the previous value.

Auto Trait Implementations§

§

impl<'a, T> RefUnwindSafe for OptionRefSwap<'a, T>where T: RefUnwindSafe,

§

impl<'a, T> Send for OptionRefSwap<'a, T>where T: Sync,

§

impl<'a, T> Sync for OptionRefSwap<'a, T>where T: Sync,

§

impl<'a, T> Unpin for OptionRefSwap<'a, T>

§

impl<'a, T> UnwindSafe for OptionRefSwap<'a, T>where T: RefUnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.