From e984e025295f8175808dd0319a5679a4e7f938c3 Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Wed, 12 Apr 2017 10:56:59 -0700 Subject: [PATCH] Pre: comment RcCounter. --- core/src/counter.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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) }