glean_core/traits/numerator.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::Rate;
6use crate::{ErrorType, TestGetValue};
7
8// When changing this trait, ensure all operations are implemented in the
9// related type in `../metrics`. (Except test_get_num_errors)
10/// A description for the `NumeratorMetric` subtype of the [`RateMetric`](crate::metrics::RateMetric) type.
11pub trait Numerator: TestGetValue<Rate> {
12 /// Increases the numerator by `amount`.
13 ///
14 /// # Arguments
15 ///
16 /// * `amount` - The amount to increase by. Should be non-negative.
17 ///
18 /// ## Notes
19 ///
20 /// Logs an error if the `amount` is negative.
21 fn add_to_numerator(&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}