Struct ref_swap::RefSwap

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

A reference that can atomically be changed using another reference with the same lifetime and type

Implementations§

source§

impl<'a, T> RefSwap<'a, T>

source

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

source

pub fn compare_and_swap( &self, current: &'a T, new: &'a T, order: Ordering ) -> &'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: &'a T, new: &'a T, success: Ordering, failure: Ordering ) -> Result<&'a T, &'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: &'a T, new: &'a T, success: Ordering, failure: Ordering ) -> Result<&'a T, &'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 get_mut<'s>(&'s mut self) -> &'s mut &'a T

Get a mutable reference to the current stored reference.

This is safe because the mutable reference guarantees that no other threads are concurrently accessing the atomic data.

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(&'a T) -> Option<&'a T>>( &self, set_order: Ordering, fetch_order: Ordering, f: F ) -> Result<&'a T, &'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) -> &'a T

Loads a value

source

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

Store a value

source

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

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<'a, T> UnwindSafe for RefSwap<'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.