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 [`StringMetric`](crate::metrics::StringMetric) type.
8 ///
9 /// When changing this trait, make sure all the operations are
10 /// implemented in the related type in `../metrics/`.
11 pub trait String {
12     /// Sets to the specified value.
13     ///
14     /// # Arguments
15     ///
16     /// * `value` - The string to set the metric to.
17     ///
18     /// ## Notes
19     ///
20     /// Truncates the value if it is longer than `MAX_LENGTH_VALUE` bytes and logs an error.
set<S: Into<std::string::String>>(&self, value: S)21     fn set<S: Into<std::string::String>>(&self, value: S);
22 
23     /// **Exported for test purposes.**
24     ///
25     /// Gets the currently stored value as a string.
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`.
test_get_value<'a, S: Into<Option<&'a str>>>( &self, ping_name: S, ) -> Option<std::string::String>33     fn test_get_value<'a, S: Into<Option<&'a str>>>(
34         &self,
35         ping_name: S,
36     ) -> Option<std::string::String>;
37 
38     /// **Exported for test purposes.**
39     ///
40     /// Gets the number of recorded errors for the given metric and error type.
41     ///
42     /// # Arguments
43     ///
44     /// * `error` - The type of error
45     /// * `ping_name` - represents the optional name of the ping to retrieve the
46     ///   metric for. Defaults to the first value in `send_in_pings`.
47     ///
48     /// # Returns
49     ///
50     /// The number of errors reported.
test_get_num_recorded_errors<'a, S: Into<Option<&'a str>>>( &self, error: ErrorType, ping_name: S, ) -> i3251     fn test_get_num_recorded_errors<'a, S: Into<Option<&'a str>>>(
52         &self,
53         error: ErrorType,
54         ping_name: S,
55     ) -> i32;
56 }
57