atomic-traits crate documentation minimum rustc 1.8 Travis status

The traits for generic atomic operations in Rust.

Compatibility

The crate is tested for stable and nightly compiler.

Usage

Add this to your Cargo.toml:

toml [dependencies] atomic-traits = "0.2"

and this to your crate root:

rust extern crate atomic_traits;

Example

```rust use std::sync::atomic::{AtomicUsize, Ordering};

use numtraits::One; use atomictraits::{Atomic, NumOps, fetch};

[derive(Debug, Default)]

pub struct RefCnt(T);

impl RefCnt where T: Atomic + NumOps + Default, ::Type: One { pub fn inc(&self) -> ::Type { self.0.fetch_add(::Type::one(), Ordering::Acquire) }

pub fn dec(&self) -> <T as Atomic>::Type {
    self.0.fetch_sub(<T as Atomic>::Type::one(), Ordering::Release)
}

pub fn val(&self) -> <T as Atomic>::Type {
    self.0.load(Ordering::SeqCst)
}

}

let refcnt = RefCnt::::default();

asserteq!(refcnt.inc(), 0); asserteq!(refcnt.dec(), 1); assert_eq!(refcnt.val(), 0); ```