@@ -6,7 +6,7 @@ use std::collections::HashMap;
66use std:: marker:: PhantomData ;
77use std:: sync:: Arc ;
88
9- use crate :: atomic64:: { Atomic , AtomicF64 , AtomicI64 , Number } ;
9+ use crate :: atomic64:: { Atomic , AtomicF64 , AtomicU64 , Number } ;
1010use crate :: desc:: Desc ;
1111use crate :: errors:: Result ;
1212use crate :: metrics:: { Collector , LocalMetric , Metric , Opts } ;
@@ -24,8 +24,8 @@ pub struct GenericCounter<P: Atomic> {
2424pub type Counter = GenericCounter < AtomicF64 > ;
2525
2626/// The integer version of [`Counter`]. Provides better performance if metric values
27- /// are all integers.
28- pub type IntCounter = GenericCounter < AtomicI64 > ;
27+ /// are all positive integers (natural numbers) .
28+ pub type IntCounter = GenericCounter < AtomicU64 > ;
2929
3030impl < P : Atomic > Clone for GenericCounter < P > {
3131 fn clone ( & self ) -> Self {
@@ -141,8 +141,8 @@ pub type GenericCounterVec<P> = MetricVec<CounterVecBuilder<P>>;
141141pub type CounterVec = GenericCounterVec < AtomicF64 > ;
142142
143143/// The integer version of [`CounterVec`]. Provides better performance if metric
144- /// values are all integers.
145- pub type IntCounterVec = GenericCounterVec < AtomicI64 > ;
144+ /// are all positive integers (natural numbers) .
145+ pub type IntCounterVec = GenericCounterVec < AtomicU64 > ;
146146
147147impl < P : Atomic > GenericCounterVec < P > {
148148 /// Create a new [`GenericCounterVec`] based on the provided
@@ -185,8 +185,8 @@ impl<P: Atomic> CounterWithValueType for GenericLocalCounter<P> {
185185pub type LocalCounter = GenericLocalCounter < AtomicF64 > ;
186186
187187/// The integer version of [`LocalCounter`]. Provides better performance
188- /// if metric values are all integers.
189- pub type LocalIntCounter = GenericLocalCounter < AtomicI64 > ;
188+ /// are all positive integers (natural numbers) .
189+ pub type LocalIntCounter = GenericLocalCounter < AtomicU64 > ;
190190
191191impl < P : Atomic > GenericLocalCounter < P > {
192192 fn new ( counter : GenericCounter < P > ) -> Self {
@@ -271,8 +271,9 @@ impl<P: Atomic> std::fmt::Debug for GenericLocalCounterVec<P> {
271271pub type LocalCounterVec = GenericLocalCounterVec < AtomicF64 > ;
272272
273273/// The integer version of [`LocalCounterVec`].
274- /// Provides better performance if metric values are all integers.
275- pub type LocalIntCounterVec = GenericLocalCounterVec < AtomicI64 > ;
274+ /// Provides better performance if metric values are all positive
275+ /// integers (natural numbers).
276+ pub type LocalIntCounterVec = GenericLocalCounterVec < AtomicU64 > ;
276277
277278impl < P : Atomic > GenericLocalCounterVec < P > {
278279 fn new ( vec : GenericCounterVec < P > ) -> Self {
@@ -588,21 +589,4 @@ mod tests {
588589 let local = counter. local ( ) ;
589590 local. inc_by ( -42.0 ) ;
590591 }
591-
592- #[ cfg( debug_assertions) ]
593- #[ test]
594- #[ should_panic( expected = "assertion failed" ) ]
595- fn test_int_counter_negative_inc ( ) {
596- let counter = IntCounter :: new ( "foo" , "bar" ) . unwrap ( ) ;
597- counter. inc_by ( -42 ) ;
598- }
599-
600- #[ cfg( debug_assertions) ]
601- #[ test]
602- #[ should_panic( expected = "assertion failed" ) ]
603- fn test_int_local_counter_negative_inc ( ) {
604- let counter = IntCounter :: new ( "foo" , "bar" ) . unwrap ( ) ;
605- let local = counter. local ( ) ;
606- local. inc_by ( -42 ) ;
607- }
608592}
0 commit comments