hopr_transport_mixer/
data.rs

1use std::cmp::Ordering;
2
3/// Data structure holding the data alongside a release timemestamp.
4///
5/// The ordering functionality is defined only over the release timestamp
6/// to ensure proper mixing.
7pub struct DelayedData<T> {
8    pub release_at: std::time::Instant,
9    pub item: T,
10}
11
12impl<T> PartialEq for DelayedData<T> {
13    fn eq(&self, other: &Self) -> bool {
14        self.release_at == other.release_at
15    }
16}
17
18impl<T> PartialOrd for DelayedData<T> {
19    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
20        Some(self.cmp(other))
21    }
22}
23
24impl<T> Eq for DelayedData<T> {}
25
26impl<T> Ord for DelayedData<T> {
27    fn cmp(&self, other: &Self) -> Ordering {
28        self.release_at.cmp(&other.release_at)
29    }
30}
31
32impl<T> From<(std::time::Instant, T)> for DelayedData<T> {
33    fn from(value: (std::time::Instant, T)) -> Self {
34        Self {
35            release_at: value.0,
36            item: value.1,
37        }
38    }
39}