glean_core/traits/
custom_distribution.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::{DistributionData, ErrorType, TestGetValue};
6
7/// A description for the
8/// [`CustomDistributionMetric`](crate::metrics::CustomDistributionMetric) type.
9///
10/// When changing this trait, make sure all the operations are
11/// implemented in the related type in `../metrics/`.
12pub trait CustomDistribution: TestGetValue<Output = DistributionData> {
13    /// Accumulates the provided signed samples in the metric.
14    ///
15    /// This is required so that the platform-specific code can provide us with
16    /// 64 bit signed integers if no `u64` comparable type is available. This
17    /// will take care of filtering and reporting errors for any provided negative
18    /// sample.
19    ///
20    /// # Arguments
21    ///
22    /// - `samples` - The vector holding the samples to be recorded by the metric.
23    ///
24    /// ## Notes
25    ///
26    /// Discards any negative value in `samples` and report an
27    /// [`ErrorType::InvalidValue`] for each of them.
28    fn accumulate_samples_signed(&self, samples: Vec<i64>);
29
30    /// Accumulates precisely one signed sample in the metric.
31    ///
32    /// This is required so that the platform-specific code can provide us with a
33    /// 64 bit signed integer if no `u64` comparable type is available. This
34    /// will take care of filtering and reporting errors.
35    ///
36    /// # Arguments
37    ///
38    /// - `sample` - The singular sample to be recorded by the metric.
39    ///
40    /// ## Notes
41    ///
42    /// Discards any negative value of `sample` and reports an
43    /// [`ErrorType::InvalidValue`].
44    fn accumulate_single_sample_signed(&self, sample: i64);
45
46    /// **Exported for test purposes.**
47    ///
48    /// Gets the number of recorded errors for the given error type.
49    ///
50    /// # Arguments
51    ///
52    /// * `error` - The type of error
53    ///
54    /// # Returns
55    ///
56    /// The number of errors recorded.
57    fn test_get_num_recorded_errors(&self, error: ErrorType) -> i32;
58}