Counter

Trait Counter 

Source
pub unsafe trait Counter<T>: Sized {
    // Required methods
    unsafe fn increment(&self);
    unsafe fn decrement(&self) -> bool;
    fn fence_acquire();
    fn one() -> Self;
}
Expand description

Counter trait for uniformed reference counting.

§Safety

The implementation must hold arithmetic invariants and respect synchronization.

Required Methods§

Source

unsafe fn increment(&self)

Increment the counter by 1.

§Safety

The caller must ensure that the counter will not overflow.

Source

unsafe fn decrement(&self) -> bool

Decrement the counter by 1.

§Returns

true if the counter reaches zero.

§Safety

The caller must ensure that the counter will not underflow.

Counter::fence_acquire must be called after this if it returns true.

Source

fn fence_acquire()

Issue an acquire fence.

Source

fn one() -> Self

Create a counter with initial value of one.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Counter<u8> for Cell<u8>

Source§

unsafe fn increment(&self)

Source§

unsafe fn decrement(&self) -> bool

Source§

fn fence_acquire()

Source§

fn one() -> Self

Source§

impl Counter<u8> for AtomicU8

Source§

unsafe fn increment(&self)

Source§

unsafe fn decrement(&self) -> bool

Source§

fn fence_acquire()

Source§

fn one() -> Self

Source§

impl Counter<u16> for Cell<u16>

Source§

unsafe fn increment(&self)

Source§

unsafe fn decrement(&self) -> bool

Source§

fn fence_acquire()

Source§

fn one() -> Self

Source§

impl Counter<u16> for AtomicU16

Source§

unsafe fn increment(&self)

Source§

unsafe fn decrement(&self) -> bool

Source§

fn fence_acquire()

Source§

fn one() -> Self

Source§

impl Counter<u32> for Cell<u32>

Source§

unsafe fn increment(&self)

Source§

unsafe fn decrement(&self) -> bool

Source§

fn fence_acquire()

Source§

fn one() -> Self

Source§

impl Counter<u32> for AtomicU32

Source§

unsafe fn increment(&self)

Source§

unsafe fn decrement(&self) -> bool

Source§

fn fence_acquire()

Source§

fn one() -> Self

Source§

impl Counter<u64> for Cell<u64>

Source§

unsafe fn increment(&self)

Source§

unsafe fn decrement(&self) -> bool

Source§

fn fence_acquire()

Source§

fn one() -> Self

Source§

impl Counter<u64> for AtomicU64

Source§

unsafe fn increment(&self)

Source§

unsafe fn decrement(&self) -> bool

Source§

fn fence_acquire()

Source§

fn one() -> Self

Source§

impl Counter<usize> for Cell<usize>

Source§

unsafe fn increment(&self)

Source§

unsafe fn decrement(&self) -> bool

Source§

fn fence_acquire()

Source§

fn one() -> Self

Source§

impl Counter<usize> for AtomicUsize

Source§

unsafe fn increment(&self)

Source§

unsafe fn decrement(&self) -> bool

Source§

fn fence_acquire()

Source§

fn one() -> Self

Implementors§