Debian Codegraph @

third_party/rust/glean-core/src/traits/quantity.rs

raw
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
5 use crate::ErrorType;
6
7 /// A description for the [`QuantityMetric`](crate::metrics::QuantityMetric) type.
8 ///
9 /// When changing this trait, make sure all the operations are
10 /// implemented in the related type in `../metrics/`.
11 pub trait Quantity {
12 /// Sets the value. Must be non-negative.
13 ///
14 /// # Arguments
15 ///
16 /// * `value` - The value. Must be non-negative.
17 ///
18 /// ## Notes
19 ///
20 /// Logs an error if the `value` is negative.
21 fn set(&self, value: i64);
22
23 /// **Exported for test purposes.**
24 ///
25 /// Gets the currently stored value as an integer.
26 ///
27 /// This doesn't clear the stored value.
28 ///
29 /// # Arguments
30 ///
31 /// * `ping_name` - represents the optional name of the ping to retrieve the
32 /// metric for. Defaults to the first value in `send_in_pings`.
33 fn test_get_value<'a, S: Into<Option<&'a str>>>(&self, ping_name: S) -> Option<i64>;
34
35 /// **Exported for test purposes.**
36 ///
37 /// Gets the number of recorded errors for the given metric and error type.
38 ///
39 /// # Arguments
40 ///
41 /// * `error` - The type of error
42 ///
43 /// # Returns
44 ///
45 /// The number of errors reported.
46 fn test_get_num_recorded_errors(&self, error: ErrorType) -> i32;
47 }