use expiration_date::error::ExpirationDateError;
use thiserror::Error;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
#[non_exhaustive]
pub enum ClockError {
#[error(
"the wall clock is unavailable: this build has no `clock` feature, so pass the time \
explicitly, through a date argument or the `*_at` form of the call where there is \
one; a time to expiry can also measure from the thread's reference datetime"
)]
Unavailable,
}
impl From<ClockError> for ExpirationDateError {
#[cold]
#[inline(never)]
fn from(err: ClockError) -> Self {
Self::InvalidDateTime(err.to_string())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_clock_error_converts_to_invalid_datetime_keeping_its_message() {
let message = ClockError::Unavailable.to_string();
let converted = ExpirationDateError::from(ClockError::Unavailable);
assert!(
matches!(converted, ExpirationDateError::InvalidDateTime(ref text) if *text == message)
);
assert!(message.contains("wall clock is unavailable"));
}
}