diff --git a/core/src/counter.rs b/core/src/counter.rs index d51faa5f..f32c0027 100644 --- a/core/src/counter.rs +++ b/core/src/counter.rs @@ -20,11 +20,24 @@ pub struct RcCounter { c: Rc, } +/// A simple shared counter. impl RcCounter { pub fn new() -> Self { RcCounter { c: Rc::new(AtomicUsize::new(0)) } } + /// Return the next value in the sequence. + /// + /// ``` + /// use mentat_core::counter::RcCounter; + /// + /// let c = RcCounter::with_initial(3); + /// assert_eq!(c.next(), 3); + /// assert_eq!(c.next(), 4); + /// let d = c.clone(); + /// assert_eq!(d.next(), 5); + /// assert_eq!(c.next(), 6); + /// ``` pub fn next(&self) -> usize { self.c.fetch_add(1, Ordering::SeqCst) }