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