Struct Atomic

Source
pub struct Atomic<S, T>(/* private fields */)
where
    S: AtomicType,
    T: From<S> + Into<S>;
Expand description

An atomic wrapper with an underlying atomic storage and conversion to a type T.

Acquire ordering is used for load and Release ordering is used for store.

A proc macro might be provided in the future to simplify declaring a compatible enum type.

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum MyEnum {
   A,
   B,
   C,
   Invalid, //
}
impl From<u8> for MyEnum {
    fn from(value: u8) -> Self {
        match value {
            0 => Self::A,
            1 => Self::B,
            2 => Self::C,
            _ => Self::Invalid,
        }
    }
}
impl From<MyEnum> for u8 {
    fn from(value: MyEnum) -> Self {
        value as Self
    }
}

let value: cu::Atomic<u8, MyEnum> = cu::Atomic::new_u8(MyEnum::A as u8);
assert_eq!(MyEnum::A, value.get());
value.set(MyEnum::C);
assert_eq!(MyEnum::C, value.get());

Implementations§

Source§

impl<T: From<i8> + Into<i8>> Atomic<i8, T>

Source

pub const fn new_i8(value: i8) -> Self

Source

pub fn get(&self) -> T

Source

pub fn set(&self, value: T)

Source§

impl<T: From<i16> + Into<i16>> Atomic<i16, T>

Source

pub const fn new_i16(value: i16) -> Self

Source

pub fn get(&self) -> T

Source

pub fn set(&self, value: T)

Source§

impl<T: From<i32> + Into<i32>> Atomic<i32, T>

Source

pub const fn new_i32(value: i32) -> Self

Source

pub fn get(&self) -> T

Source

pub fn set(&self, value: T)

Source§

impl<T: From<i64> + Into<i64>> Atomic<i64, T>

Source

pub const fn new_i64(value: i64) -> Self

Source

pub fn get(&self) -> T

Source

pub fn set(&self, value: T)

Source§

impl<T: From<u8> + Into<u8>> Atomic<u8, T>

Source

pub const fn new_u8(value: u8) -> Self

Source

pub fn get(&self) -> T

Source

pub fn set(&self, value: T)

Source§

impl<T: From<u16> + Into<u16>> Atomic<u16, T>

Source

pub const fn new_u16(value: u16) -> Self

Source

pub fn get(&self) -> T

Source

pub fn set(&self, value: T)

Source§

impl<T: From<u32> + Into<u32>> Atomic<u32, T>

Source

pub const fn new_u32(value: u32) -> Self

Source

pub fn get(&self) -> T

Source

pub fn set(&self, value: T)

Source§

impl<T: From<u64> + Into<u64>> Atomic<u64, T>

Source

pub const fn new_u64(value: u64) -> Self

Source

pub fn get(&self) -> T

Source

pub fn set(&self, value: T)

Source§

impl<T: From<bool> + Into<bool>> Atomic<bool, T>

Source

pub const fn new_bool(value: bool) -> Self

Source

pub fn get(&self) -> T

Source

pub fn set(&self, value: T)

Source§

impl<T: From<isize> + Into<isize>> Atomic<isize, T>

Source

pub const fn new_isize(value: isize) -> Self

Source

pub fn get(&self) -> T

Source

pub fn set(&self, value: T)

Source§

impl<T: From<usize> + Into<usize>> Atomic<usize, T>

Source

pub const fn new_usize(value: usize) -> Self

Source

pub fn get(&self) -> T

Source

pub fn set(&self, value: T)

Trait Implementations§

Source§

impl<S, T> Debug for Atomic<S, T>
where S: AtomicType + Debug, T: From<S> + Into<S> + Debug, S::Type: Debug,

Source§

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

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

impl<S, T> Default for Atomic<S, T>
where S: AtomicType + Default, T: From<S> + Into<S> + Default, S::Type: Default,

Source§

fn default() -> Atomic<S, T>

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

Auto Trait Implementations§

§

impl<S, T> Freeze for Atomic<S, T>
where <S as AtomicType>::Type: Freeze,

§

impl<S, T> RefUnwindSafe for Atomic<S, T>

§

impl<S, T> Send for Atomic<S, T>
where <S as AtomicType>::Type: Send, T: Send,

§

impl<S, T> Sync for Atomic<S, T>
where <S as AtomicType>::Type: Sync, T: Sync,

§

impl<S, T> Unpin for Atomic<S, T>
where <S as AtomicType>::Type: Unpin, T: Unpin,

§

impl<S, T> UnwindSafe for Atomic<S, T>
where <S as AtomicType>::Type: UnwindSafe, T: UnwindSafe,

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.