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>
impl<'a, T> OptionRefSwap<'a, T>
pub const fn new(data: Option<&'a T>) -> Self
sourcepub 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
pub fn compare_and_swap( &self, current: Option<&'a T>, new: Option<&'a T>, order: Ordering ) -> Option<&'a T>
compare_exchange
or compare_exchange_weak
insteadStores 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
sourcepub fn compare_exchange(
&self,
current: Option<&'a T>,
new: Option<&'a T>,
success: Ordering,
failure: Ordering
) -> Result<Option<&'a T>, Option<&'a T>>
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
sourcepub fn compare_exchange_weak(
&self,
current: Option<&'a T>,
new: Option<&'a T>,
success: Ordering,
failure: Ordering
) -> Result<Option<&'a T>, Option<&'a T>>
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
sourcepub fn into_inner(self) -> &'a T
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.
sourcepub 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>>
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