1use std::fmt::{self, Display, Formatter};
2
3#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct Error<E> {
6 pub error: E,
8 pub attempts: usize,
10}
11
12impl<E> Error<E> {
13 pub const fn new(error: E, attempts: usize) -> Self {
15 Self {
16 error,
17 attempts,
18 }
19 }
20
21 pub fn into_inner(self) -> E {
23 self.error
24 }
25
26 pub const fn inner(&self) -> &E {
28 &self.error
29 }
30
31 pub const fn attempts(&self) -> usize {
33 self.attempts
34 }
35}
36
37impl<E: Display> Display for Error<E> {
38 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
39 write!(f, "retry failed after {} attempts: {}", self.attempts, self.error)
40 }
41}
42
43impl<E: Display + std::fmt::Debug> std::error::Error for Error<E> {}