]> git.proxmox.com Git - proxmox-backup.git/commitdiff
rrd: add Entry::get() to access the data
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 24 Nov 2022 12:52:43 +0000 (13:52 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 24 Nov 2022 12:53:49 +0000 (13:53 +0100)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
proxmox-rrd/src/rrd.rs

index 6affa9a5f451b6a52c4a3581ff4bcb16cfd8f1da..7d05072f7e83bed9d5e296d3acd081f8add158d5 100644 (file)
@@ -90,6 +90,12 @@ impl Entry {
             data,
         }
     }
+
+    /// Get a data point at a specific index which also does bound checking and returns `None` for
+    /// out of bounds indices.
+    pub fn get(&self, idx: usize) -> Option<f64> {
+        self.data.get(idx).copied().flatten()
+    }
 }
 
 impl From<Entry> for (u64, u64, Vec<Option<f64>>) {