Skip to main content

PotentialAtomicOption

Struct PotentialAtomicOption 

Source
pub struct PotentialAtomicOption<T, W: PotentialWell>(/* private fields */);
Expand description

Type-hoisted AtomicOption.

Uses PotentialWell to allow for recursive structures at the cost of some usability. See the documentation for PotentialWell for more information.

Implementations§

Source§

impl<T, W: PotentialWell> PotentialAtomicOption<T, W>

Source

pub fn none() -> PotentialAtomicOption<T, W>

Creates atomic without anything inside.

Source

pub fn some(well: KineticWell<T, W>) -> PotentialAtomicOption<T, W>

Creates atomic with something inside.

Source

pub fn new(well: Option<KineticWell<T, W>>) -> PotentialAtomicOption<T, W>

Creates atomic.

Source

pub unsafe fn as_raw_unchecked(&self) -> &AtomicPtr<T>

Gives access to the underlying AtomicPtr.

§Safety

The pointer inside the atomic must always be null, or a valid pointer from Well::remove. Additionally, keep in mind that this atomic owns the pointer, and if you want to move it out, you must put a different pointer in its place first.

Source

pub fn swap( &self, well: KineticWell<T, W>, ordering: Ordering, ) -> Option<KineticWell<T, W>>

Atomically swaps the data inside the well.

This is equivalent to an atomic swap.

Source

pub fn take(&self, ordering: Ordering) -> Option<KineticWell<T, W>>

Takes the data out of the well.

This is equivalent to an atomic swap with a null pointer.

Source

pub fn insert( &self, well: KineticWell<T, W>, success: Ordering, failure: Ordering, ) -> Result<(), KineticWell<T, W>>

Inserts data into the well.

This uses compare_exchange to avoid inserting into the well if it’s already full. If you want to use compare_exchange_weak instead, use insert_weak.

Source

pub fn insert_weak( &self, well: KineticWell<T, W>, success: Ordering, failure: Ordering, ) -> Result<(), KineticWell<T, W>>

Inserts data into the well, sometimes failing spuriously.

This uses compare_exchange_weak to avoid inserting into the well if it’s already full, which may spuriously fail. If you want to use compare_exchange instead, use insert.

Source§

impl<T, W: PotentialWell> PotentialAtomicOption<T, W>
where KineticWell<T, W>: StrongWell + Deref<Target = T>,

Source

pub fn load(&self, ordering: Ordering) -> Option<&T>

Loads the inner data as an immutable reference.

This is equivalent to an atomic load.

Source

pub fn swap_get( &self, well: KineticWell<T, W>, ordering: Ordering, ) -> (Option<KineticWell<T, W>>, &T)

Atomically swaps the data inside the well and returns a reference to the new data.

This is swap, but with the unsafe deref hidden behind a safe API.

Source

pub fn insert_get( &self, well: KineticWell<T, W>, success: Ordering, failure: Ordering, ) -> Result<&T, KineticWell<T, W>>

Inserts data into the well and returns a reference to the new data.

This is insert, but with the unsafe deref hidden behind a safe API.

Source

pub fn insert_weak_get( &self, well: KineticWell<T, W>, success: Ordering, failure: Ordering, ) -> Result<&T, KineticWell<T, W>>

Inserts data into the well, returns reference to the new data, sometimes failing spuriously.

This is insert_weak, but with the unsafe deref hidden behind a safe API.

Source§

impl<T: Unpin, W: PotentialWell> PotentialAtomicOption<T, W>
where KineticWell<T, W>: StrongWellMut + Deref<Target = T>,

Source

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

Loads the inner data as a mutable reference.

This performs a non-atomic access since the atomic is mutably borrowed.

Source§

impl<T, W: PotentialWell> PotentialAtomicOption<T, Pin<W>>
where KineticWell<T, W>: StrongWellMut + Deref<Target = T>, Pin<W>: PotentialWell<Well<T> = Pin<KineticWell<T, W>>>,

Source

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

Loads the inner data as a pinned mutable reference.

This is a version of load_mut that works with pinned values.

Source§

impl<T, W: PotentialWell> PotentialAtomicOption<T, W>
where KineticWell<T, W>: Clone,

Source

pub fn load_clone(&self, ordering: Ordering) -> Option<KineticWell<T, W>>

Loads a clone of the inner data.

This still performs an atomic load, but instead of offering a reference, the smart pointer is cloned instead.

Trait Implementations§

Source§

impl<T, W: PotentialWell> Debug for PotentialAtomicOption<T, W>
where KineticWell<T, W>: Debug,

Source§

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

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

impl<T, W: PotentialWell> Default for PotentialAtomicOption<T, W>

By default, nothing is stored in the atomic.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T, W: PotentialWell> From<Option<<W as PotentialWell>::Well<T>>> for PotentialAtomicOption<T, W>

Source§

fn from(well: Option<KineticWell<T, W>>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T, W> !Freeze for PotentialAtomicOption<T, W>

§

impl<T, W> RefUnwindSafe for PotentialAtomicOption<T, W>
where <W as PotentialWell>::Well<T>: RefUnwindSafe,

§

impl<T, W> Send for PotentialAtomicOption<T, W>
where <W as PotentialWell>::Well<T>: Send,

§

impl<T, W> Sync for PotentialAtomicOption<T, W>
where <W as PotentialWell>::Well<T>: Sync,

§

impl<T, W> Unpin for PotentialAtomicOption<T, W>
where <W as PotentialWell>::Well<T>: Unpin,

§

impl<T, W> UnsafeUnpin for PotentialAtomicOption<T, W>

§

impl<T, W> UnwindSafe for PotentialAtomicOption<T, W>

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<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.