glean_core/traits/rate.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// When changing this trait, ensure all operations are implemented in the
8// related type in `../metrics`. (Except test_get_num_errors)
9/// A description for the [`RateMetric`](crate::metrics::RateMetric) type.
10pub trait Rate: TestGetValue<Output = crate::Rate> {
11 /// Increases the numerator by `amount`.
12 ///
13 /// # Arguments
14 ///
15 /// * `amount` - The amount to increase by. Should be non-negative.
16 ///
17 /// ## Notes
18 ///
19 /// Logs an error if the `amount` is negative.
20 fn add_to_numerator(&self, amount: i32);
21
22 /// Increases the denominator by `amount`.
23 ///
24 /// # Arguments
25 ///
26 /// * `amount` - The amount to increase by. Should be non-negative.
27 ///
28 /// ## Notes
29 ///
30 /// Logs an error if the `amount` is negative.
31 fn add_to_denominator(&self, amount: i32);
32
33 /// **Exported for test purposes.**
34 ///
35 /// Gets the number of recorded errors for the given metric and error type.
36 ///
37 /// # Arguments
38 ///
39 /// * `error` - The type of error
40 ///
41 /// # Returns
42 ///
43 /// The number of errors reported.
44 fn test_get_num_recorded_errors(&self, error: ErrorType) -> i32;
45}