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, TestGetValue};
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: TestGetValue<Output = Vec<String>> {
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 number of recorded errors for the given error type.
39    ///
40    /// # Arguments
41    ///
42    /// * `error` - The type of error
43    ///
44    /// # Returns
45    ///
46    /// The number of errors recorded.
47    fn test_get_num_recorded_errors(&self, error: ErrorType) -> i32;
48}