1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use ic_agent::agent::{QueryBuilder, UpdateBuilder};
#[derive(Clone, Debug, Ord, PartialOrd, Eq, PartialEq)]
pub enum Expiry {
Unspecified,
Delay(std::time::Duration),
DateTime(std::time::SystemTime),
}
impl Expiry {
#[inline]
pub fn after(d: std::time::Duration) -> Self {
Self::Delay(d)
}
#[inline]
pub fn at(dt: std::time::SystemTime) -> Self {
Self::DateTime(dt)
}
pub(crate) fn apply_to_update(self, u: &mut UpdateBuilder<'_>) {
match self {
Expiry::Unspecified => {}
Expiry::Delay(d) => {
u.expire_after(d);
}
Expiry::DateTime(dt) => {
u.expire_at(dt);
}
}
}
pub(crate) fn apply_to_query(self, u: &mut QueryBuilder<'_>) {
match self {
Expiry::Unspecified => {}
Expiry::Delay(d) => {
u.expire_after(d);
}
Expiry::DateTime(dt) => {
u.expire_at(dt);
}
}
}
}
impl From<std::time::Duration> for Expiry {
fn from(d: std::time::Duration) -> Self {
Self::Delay(d)
}
}
impl From<std::time::SystemTime> for Expiry {
fn from(dt: std::time::SystemTime) -> Self {
Self::DateTime(dt)
}
}
impl Default for Expiry {
fn default() -> Self {
Expiry::Unspecified
}
}