@@ -104,34 +104,33 @@ impl Counter {
104
104
}
105
105
106
106
/// Increases the [`Counter`] by `u64`, returning the previous value.
107
- #[ cfg( feature = "metrics" ) ]
108
107
pub fn inc_by ( & self , v : u64 ) -> u64 {
109
- self . counter . inc_by ( v)
108
+ #[ cfg( feature = "metrics" ) ]
109
+ {
110
+ self . counter . inc_by ( v)
111
+ }
112
+ #[ cfg( not( feature = "metrics" ) ) ]
113
+ {
114
+ let _ = v;
115
+ 0
116
+ }
110
117
}
111
118
112
- /// Sets the [`Counter`] value.
119
+ /// Sets the [`Counter`] value, returning the previous value .
113
120
///
114
121
/// Warning: this is not default behavior for a counter that should always be monotonically increasing.
115
- #[ cfg( feature = "metrics" ) ]
116
122
pub fn set ( & self , v : u64 ) -> u64 {
117
- self . counter
118
- . inner ( )
119
- . store ( v, std:: sync:: atomic:: Ordering :: Relaxed ) ;
120
- v
121
- }
122
-
123
- /// Sets the [`Counter`] value.
124
- ///
125
- /// Warning: this is not default behavior for a counter that should always be monotonically increasing.
126
- #[ cfg( not( feature = "metrics" ) ) ]
127
- pub fn set ( & self , _v : u64 ) -> u64 {
128
- 0
129
- }
130
-
131
- /// Increases the [`Counter`] by `u64`, returning the previous value.
132
- #[ cfg( not( feature = "metrics" ) ) ]
133
- pub fn inc_by ( & self , _v : u64 ) -> u64 {
134
- 0
123
+ #[ cfg( feature = "metrics" ) ]
124
+ {
125
+ self . counter
126
+ . inner ( )
127
+ . swap ( v, std:: sync:: atomic:: Ordering :: Relaxed )
128
+ }
129
+ #[ cfg( not( feature = "metrics" ) ) ]
130
+ {
131
+ let _ = v;
132
+ 0
133
+ }
135
134
}
136
135
137
136
/// Returns the current value of the [`Counter`].
@@ -194,15 +193,16 @@ impl Gauge {
194
193
}
195
194
196
195
/// Increases the [`Gauge`] by `i64`, returning the previous value.
197
- #[ cfg( feature = "metrics" ) ]
198
196
pub fn inc_by ( & self , v : i64 ) -> i64 {
199
- self . gauge . inc_by ( v)
200
- }
201
-
202
- /// Increases the [`Gauge`] by `i64`, returning the previous value.
203
- #[ cfg( not( feature = "metrics" ) ) ]
204
- pub fn inc_by ( & self , _v : u64 ) -> u64 {
205
- 0
197
+ #[ cfg( feature = "metrics" ) ]
198
+ {
199
+ self . gauge . inc_by ( v)
200
+ }
201
+ #[ cfg( not( feature = "metrics" ) ) ]
202
+ {
203
+ let _ = v;
204
+ 0
205
+ }
206
206
}
207
207
208
208
/// Decreases the [`Gauge`] by 1, returning the previous value.
@@ -216,43 +216,38 @@ impl Gauge {
216
216
}
217
217
218
218
/// Decreases the [`Gauge`] by `i64`, returning the previous value.
219
- #[ cfg( feature = "metrics" ) ]
220
219
pub fn dec_by ( & self , v : i64 ) -> i64 {
221
- self . gauge . dec_by ( v)
222
- }
223
-
224
- /// Decreases the [`Gauge`] by `i64`, returning the previous value.
225
- #[ cfg( not( feature = "metrics" ) ) ]
226
- pub fn dec_by ( & self , _v : u64 ) -> u64 {
227
- 0
220
+ #[ cfg( feature = "metrics" ) ]
221
+ {
222
+ self . gauge . dec_by ( v)
223
+ }
224
+ #[ cfg( not( feature = "metrics" ) ) ]
225
+ {
226
+ let _ = v;
227
+ 0
228
+ }
228
229
}
229
230
230
- /// Sets the [`Gauge`] value.
231
- #[ cfg( feature = "metrics" ) ]
231
+ /// Sets the [`Gauge`] to `v`, returning the previous value.
232
232
pub fn set ( & self , v : i64 ) -> i64 {
233
- self . gauge
234
- . inner ( )
235
- . store ( v, std:: sync:: atomic:: Ordering :: Relaxed ) ;
236
- v
237
- }
238
-
239
- /// Sets the [`Gauge`] value.
240
- #[ cfg( not( feature = "metrics" ) ) ]
241
- pub fn set ( & self , _v : i64 ) -> i64 {
242
- 0
243
- }
244
-
245
- /// Returns the [`Gauge`] value.
246
- #[ cfg( feature = "metrics" ) ]
247
- pub fn get ( & self ) -> i64 {
248
- self . gauge
249
- . inner ( )
250
- . load ( std:: sync:: atomic:: Ordering :: Relaxed )
233
+ #[ cfg( feature = "metrics" ) ]
234
+ {
235
+ self . gauge . set ( v)
236
+ }
237
+ #[ cfg( not( feature = "metrics" ) ) ]
238
+ {
239
+ let _ = v;
240
+ 0
241
+ }
251
242
}
252
243
253
244
/// Returns the [`Gauge`] value.
254
- #[ cfg( not( feature = "metrics" ) ) ]
255
245
pub fn get ( & self ) -> i64 {
246
+ #[ cfg( feature = "metrics" ) ]
247
+ {
248
+ self . gauge . get ( )
249
+ }
250
+ #[ cfg( not( feature = "metrics" ) ) ]
256
251
0
257
252
}
258
253
}
0 commit comments