Skip to content

Commit 6a06637

Browse files
committed
Implement Display for Sample
Signed-off-by: Sahas Subramanian <sahas.subramanian@proton.me>
1 parent d847c38 commit 6a06637

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/sample.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,26 @@ use chrono::{DateTime, Utc};
55

66
/// Represents a measurement of a microgrid metric, made at a specific time.
77
#[derive(Copy, Clone, Debug, Default)]
8-
pub struct Sample<Q: Copy + Clone + std::fmt::Debug + Default> {
8+
pub struct Sample<Q: Copy + Clone + std::fmt::Debug + Default + std::fmt::Display> {
99
pub(crate) timestamp: DateTime<Utc>,
1010
pub(crate) value: Option<Q>,
1111
}
1212

13-
impl<Q: Copy + Clone + Default + std::fmt::Debug> frequenz_resampling::Sample for Sample<Q> {
13+
impl<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+
25+
impl<Q: Copy + Clone + Default + std::fmt::Debug + std::fmt::Display> frequenz_resampling::Sample
26+
for Sample<Q>
27+
{
1428
type Value = Q;
1529

1630
fn new(timestamp: DateTime<Utc>, value: Option<Self::Value>) -> Self {
@@ -26,7 +40,7 @@ impl<Q: Copy + Clone + Default + std::fmt::Debug> frequenz_resampling::Sample fo
2640
}
2741
}
2842

29-
impl<Q: Copy + Clone + Default + std::fmt::Debug> Sample<Q> {
43+
impl<Q: Copy + Clone + Default + std::fmt::Debug + std::fmt::Display> Sample<Q> {
3044
/// Creates a new `Sample` with the given timestamp and value.
3145
pub fn new(timestamp: DateTime<Utc>, value: Option<Q>) -> Self {
3246
Self { timestamp, value }

0 commit comments

Comments
 (0)