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§
Trait Implementations§
Auto Trait Implementations§
impl<S, T> Freeze for Atomic<S, T>
impl<S, T> RefUnwindSafe for Atomic<S, T>
impl<S, T> Send for Atomic<S, T>
impl<S, T> Sync for Atomic<S, T>
impl<S, T> Unpin for Atomic<S, T>
impl<S, T> UnwindSafe for Atomic<S, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more