glean_core/traits/
string_list.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 [`StringListMetric`](crate::metrics::StringListMetric) type.
8///
9/// When changing this trait, make sure all the operations are
10/// implemented in the related type in `../metrics/`.
11pub trait StringList {
12    /// Adds a new string to the list.
13    ///
14    /// # Arguments
15    ///
16    /// * `value` - The string to add.
17    ///
18    /// ## Notes
19    ///
20    /// Truncates the value if it is longer than `MAX_STRING_LENGTH` bytes and logs an error.
21    fn add<S: Into<String>>(&self, value: S);
22
23    /// Sets to a specific list of strings.
24    ///
25    /// # Arguments
26    ///
27    /// * `value` - The list of string to set the metric to.
28    ///
29    /// ## Notes
30    ///
31    /// If passed an empty list, records an error and returns.
32    /// Truncates the list if it is longer than `MAX_LIST_LENGTH` and logs an error.
33    /// Truncates any value in the list if it is longer than `MAX_STRING_LENGTH` and logs an error.
34    fn set(&self, value: Vec<String>);
35
36    /// **Exported for test purposes.**
37    ///
38    /// Gets the currently-stored values.
39    ///
40    /// This doesn't clear the stored value.
41    ///
42    /// # Arguments
43    ///
44    /// * `ping_name` - represents the optional name of the ping to retrieve the
45    ///   metric for. Defaults to the first value in `send_in_pings`.
46    fn test_get_value<'a, S: Into<Option<&'a str>>>(&self, ping_name: S) -> Option<Vec<String>>;
47
48    /// **Exported for test purposes.**
49    ///
50    /// Gets the number of recorded errors for the given error type.
51    ///
52    /// # Arguments
53    ///
54    /// * `error` - The type of error
55    ///
56    /// # Returns
57    ///
58    /// The number of errors recorded.
59    fn test_get_num_recorded_errors(&self, error: ErrorType) -> i32;
60}