use std::time::SystemTime;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Expiration {
DateTime(SystemTime),
Session,
}
impl Expiration {
pub fn is_datetime(&self) -> bool {
match self {
Expiration::DateTime(_) => true,
Expiration::Session => false
}
}
pub fn is_session(&self) -> bool {
match self {
Expiration::DateTime(_) => false,
Expiration::Session => true
}
}
pub fn datetime(self) -> Option<SystemTime> {
match self {
Expiration::Session => None,
Expiration::DateTime(v) => Some(v)
}
}
pub fn map<F>(self, f: F) -> Self
where F: FnOnce(SystemTime) -> SystemTime
{
match self {
Expiration::Session => Expiration::Session,
Expiration::DateTime(v) => Expiration::DateTime(f(v)),
}
}
}
impl From<SystemTime> for Expiration {
fn from(datetime: SystemTime) -> Self {
Expiration::DateTime(datetime)
}
}
impl From<Option<SystemTime>> for Expiration {
fn from(option: Option<SystemTime>) -> Self {
match option {
Some(value) => Expiration::DateTime(value),
None => Expiration::Session
}
}
}