metrics_runtime/data/
snapshot.rs

1use crate::common::Measurement;
2use metrics_core::Key;
3
4/// A collection of point-in-time metric measurements.
5#[derive(Default, Debug)]
6pub struct Snapshot {
7    measurements: Vec<(Key, Measurement)>,
8}
9
10impl Snapshot {
11    pub(crate) fn new(measurements: Vec<(Key, Measurement)>) -> Self {
12        Self { measurements }
13    }
14
15    /// Number of measurements in this snapshot.
16    pub fn len(&self) -> usize {
17        self.measurements.len()
18    }
19
20    /// Whether or not the snapshot is empty.
21    pub fn is_empty(&self) -> bool {
22        self.measurements.len() != 0
23    }
24
25    /// Converts a [`Snapshot`] into the internal measurements.
26    pub fn into_measurements(self) -> Vec<(Key, Measurement)> {
27        self.measurements
28    }
29}