glean_core/traits/counter.rs
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5use crate::{ErrorType, TestGetValue};
6
7/// A description for the [`CounterMetric`](crate::metrics::CounterMetric) type.
8///
9/// When changing this trait, make sure all the operations are
10/// implemented in the related type in `../metrics/`.
11pub trait Counter: TestGetValue<Output = i32> {
12 /// Increases the counter by `amount`.
13 ///
14 /// # Arguments
15 ///
16 /// * `amount` - The amount to increase by. Should be positive.
17 ///
18 /// ## Notes
19 ///
20 /// Logs an error if the `amount` is 0 or negative.
21 fn add(&self, amount: i32);
22
23 /// **Exported for test purposes.**
24 ///
25 /// Gets the number of recorded errors for the given metric and error type.
26 ///
27 /// # Arguments
28 ///
29 /// * `error` - The type of error
30 ///
31 /// # Returns
32 ///
33 /// The number of errors reported.
34 fn test_get_num_recorded_errors(&self, error: ErrorType) -> i32;
35}