frequenz_microgrid/
sample.rs1use chrono::{DateTime, Utc};
5
6#[derive(Copy, Clone, Debug, Default)]
8pub struct Sample<Q: Copy + Clone + std::fmt::Debug + Default + std::fmt::Display> {
9 pub(crate) timestamp: DateTime<Utc>,
10 pub(crate) value: Option<Q>,
11}
12
13impl<Q: crate::quantity::Quantity> std::fmt::Display for Sample<Q> {
14 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
15 write!(f, "Sample({}, ", self.timestamp)?;
16
17 if let Some(value) = self.value {
18 write!(f, " {})", value)
19 } else {
20 write!(f, " None)")
21 }
22 }
23}
24
25impl<Q: Copy + Clone + Default + std::fmt::Debug + std::fmt::Display> frequenz_resampling::Sample
26 for Sample<Q>
27{
28 type Value = Q;
29
30 fn new(timestamp: DateTime<Utc>, value: Option<Self::Value>) -> Self {
31 Self { timestamp, value }
32 }
33
34 fn timestamp(&self) -> DateTime<Utc> {
35 self.timestamp
36 }
37
38 fn value(&self) -> Option<Self::Value> {
39 self.value
40 }
41}
42
43impl<Q: Copy + Clone + Default + std::fmt::Debug + std::fmt::Display> Sample<Q> {
44 pub fn new(timestamp: DateTime<Utc>, value: Option<Q>) -> Self {
46 Self { timestamp, value }
47 }
48
49 pub fn timestamp(&self) -> DateTime<Utc> {
51 self.timestamp
52 }
53
54 pub fn value(&self) -> Option<Q> {
56 self.value
57 }
58}