use jiff::Zoned;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Expiration {
DateTime(Zoned),
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<&Zoned> {
match self {
Expiration::Session => None,
Expiration::DateTime(v) => Some(v),
}
}
pub fn map<F>(self, f: F) -> Self
where
F: FnOnce(Zoned) -> Zoned,
{
match self {
Expiration::Session => Expiration::Session,
Expiration::DateTime(v) => Expiration::DateTime(f(v)),
}
}
}
impl<T: Into<Option<Zoned>>> From<T> for Expiration {
fn from(option: T) -> Self {
match option.into() {
Some(value) => Expiration::DateTime(value),
None => Expiration::Session,
}
}
}