use std::fmt;
use std::time::Duration;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RetryAttemptFailure<E> {
Error(E),
AttemptTimeout {
elapsed: Duration,
timeout: Duration,
},
}
impl<E> RetryAttemptFailure<E> {
#[inline]
pub fn as_error(&self) -> Option<&E> {
match self {
Self::Error(error) => Some(error),
Self::AttemptTimeout { .. } => None,
}
}
#[inline]
pub fn into_error(self) -> Option<E> {
match self {
Self::Error(error) => Some(error),
Self::AttemptTimeout { .. } => None,
}
}
}
impl<E> fmt::Display for RetryAttemptFailure<E>
where
E: fmt::Display,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Error(error) => write!(f, "{error}"),
Self::AttemptTimeout { elapsed, timeout } => {
write!(
f,
"attempt timed out after {elapsed:?}; timeout was {timeout:?}"
)
}
}
}
}