sameold/receiver/
timeddata.rs

1/// Time-sensitive data with an expiration time
2#[derive(Clone, Debug, PartialEq, Eq)]
3pub struct TimedData<D> {
4    /// Data
5    pub data: D,
6
7    /// Deadline or expiration time, using monotonic SAME symbol counter
8    pub deadline: u64,
9}
10
11impl<D> TimedData<D>
12where
13    D: Clone + PartialEq + Eq,
14{
15    /// Store `data` with the given `deadline`
16    pub fn with_deadline(data: D, deadline: u64) -> Self {
17        TimedData { data, deadline }
18    }
19
20    /// Check for expiration
21    pub fn is_expired_at(&self, now: u64) -> bool {
22        self.deadline <= now
23    }
24}
25
26impl<D> AsRef<D> for TimedData<D>
27where
28    D: Clone + PartialEq + Eq,
29{
30    fn as_ref(&self) -> &D {
31        &self.data
32    }
33}