kutil 0.0.6

Kutil utilities collection
Documentation
use std::sync::atomic::*;

//
// Counter
//

/// Thread-safe counter.
#[derive(Debug)]
pub struct Counter(AtomicUsize);

impl Counter {
    /// Constructor.
    pub const fn new() -> Self {
        Self(AtomicUsize::new(0))
    }

    /// Next value.
    pub fn next(&self) -> usize {
        self.0.fetch_add(1, Ordering::SeqCst)
    }
}

impl Default for Counter {
    fn default() -> Self {
        Self::new()
    }
}