fluxion_stream_time/
instant_timestamped.rs1use core::cmp::Ordering;
6use core::fmt::Debug;
7use core::ops::Deref;
8use fluxion_core::{HasTimestamp, Timestamped};
9use fluxion_runtime::runtime::Runtime;
10
11#[derive(Debug)]
36pub struct InstantTimestamped<T, R: Runtime> {
37 pub value: T,
38 pub timestamp: R::Instant,
39}
40
41impl<T, R: Runtime> Clone for InstantTimestamped<T, R>
42where
43 T: Clone,
44{
45 fn clone(&self) -> Self {
46 Self {
47 value: self.value.clone(),
48 timestamp: self.timestamp,
49 }
50 }
51}
52
53impl<T, R: Runtime> InstantTimestamped<T, R> {
54 pub fn new(value: T, timestamp: R::Instant) -> Self {
56 Self { value, timestamp }
57 }
58}
59
60impl<T, R: Runtime> HasTimestamp for InstantTimestamped<T, R> {
61 type Timestamp = R::Instant;
62
63 fn timestamp(&self) -> Self::Timestamp {
64 self.timestamp
65 }
66}
67
68impl<T, R: Runtime> Timestamped for InstantTimestamped<T, R>
69where
70 T: Clone,
71{
72 type Inner = T;
73
74 fn into_inner(self) -> Self::Inner {
75 self.value
76 }
77
78 fn with_timestamp(inner: Self::Inner, timestamp: Self::Timestamp) -> Self {
79 Self::new(inner, timestamp)
80 }
81}
82
83impl<T, R: Runtime> PartialEq for InstantTimestamped<T, R>
84where
85 T: PartialEq,
86{
87 fn eq(&self, other: &Self) -> bool {
88 self.timestamp == other.timestamp && self.value == other.value
89 }
90}
91
92impl<T, R: Runtime> Eq for InstantTimestamped<T, R> where T: Eq {}
93
94impl<T, R: Runtime> PartialOrd for InstantTimestamped<T, R>
95where
96 T: PartialOrd,
97{
98 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
99 self.timestamp.partial_cmp(&other.timestamp)
100 }
101}
102
103impl<T, R: Runtime> Ord for InstantTimestamped<T, R>
104where
105 T: Ord,
106{
107 fn cmp(&self, other: &Self) -> Ordering {
108 self.timestamp.cmp(&other.timestamp)
109 }
110}
111
112impl<T, R: Runtime> Deref for InstantTimestamped<T, R> {
113 type Target = T;
114
115 fn deref(&self) -> &Self::Target {
116 &self.value
117 }
118}