Skip to main content

Atomic

Struct Atomic 

Source
pub struct Atomic<W: Well>(/* private fields */);
Expand description

Atomic potential well.

Internally, this just wraps a pointer to Bucket<T> and uses atomic pointer operations to access it. However, the number of operations on the pointer is limited to ensure correctness in safe code.

Implementations§

Source§

impl<W: Well> Atomic<W>

Source

pub fn new(well: W) -> Atomic<W>

Creates atomic with a value.

Source

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

Gives access to the underlying AtomicPtr.

§Safety

The pointer inside the atomic must always a valid pointer from Well::remove and therefore must not be null. 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: W, ordering: Ordering) -> W

Atomically swaps the data inside the well.

This is equivalent to an atomic swap.

Source§

impl<W: WeakWell> Atomic<W>

Source

pub fn try_load(&self, ordering: Ordering) -> Option<<W as WeakWell>::Strong>

Tries to load the inner data.

This is equivalent to an atomic load, but it may fail due to the weak reference.

Source§

impl<W: StrongWell + Deref<Target: Sized>> Atomic<W>

Source

pub fn load(&self, ordering: Ordering) -> &Target<W>

Loads the inner data as an immutable reference.

This is equivalent to an atomic load.

Source

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

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§

impl<W: StrongWellMut + DerefMut<Target: Unpin>> Atomic<W>

Source

pub fn load_mut(&mut self) -> &mut Target<W>

Loads the inner data as a mutable reference.

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

Source§

impl<W: StrongWellMut> Atomic<Pin<W>>

Source

pub fn load_mut_pinned(&mut self) -> Pin<&mut <Pin<W> as Well>::Target>

Loads the inner data as a mutable reference.

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

Source§

impl<W: Well + Clone> Atomic<W>

Source

pub fn load_clone(&self, ordering: Ordering) -> 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<W: Well + Debug> Debug for Atomic<W>

Source§

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

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

impl<W: Well + Default> Default for Atomic<W>

Source§

fn default() -> Self

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

impl<W: Well> Drop for Atomic<W>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<W: Well> From<W> for Atomic<W>

Source§

fn from(well: W) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<W> !Freeze for Atomic<W>

§

impl<W> RefUnwindSafe for Atomic<W>

§

impl<W> Send for Atomic<W>

§

impl<W> Sync for Atomic<W>

§

impl<W> Unpin for Atomic<W>

§

impl<W> UnsafeUnpin for Atomic<W>

§

impl<W> UnwindSafe for Atomic<W>
where <W as Well>::Target: RefUnwindSafe,

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.