use std::time::{Duration, Instant};
pub const NEVER_EXPIRE_TTL: Duration = Duration::from_secs(200 * 365 * 24 * 60 * 60);
#[derive(Debug, Clone, Copy)]
pub struct Expiry(Instant);
impl Expiry {
pub fn from_now(ttl: Duration) -> Self {
let expiry = Instant::now()
.checked_add(ttl)
.expect("TTL value should not overflow 64-bit time");
Self(expiry)
}
pub fn remaining_ttl(&self) -> Duration {
self.0.saturating_duration_since(Instant::now())
}
pub fn is_expired(&self) -> bool {
self.0 < Instant::now()
}
}