Skip to content

Commit b08b763

Browse files
committed
Remove todos
1 parent 8151938 commit b08b763

File tree

1 file changed

+29
-34
lines changed

1 file changed

+29
-34
lines changed

src/error.rs

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -89,31 +89,6 @@ pub enum ErrorKind {
8989
UnexpectedEof,
9090
}
9191

92-
impl ErrorKind {
93-
pub(crate) fn as_str(&self) -> &'static str {
94-
match *self {
95-
ErrorKind::NotFound => "entity not found",
96-
ErrorKind::PermissionDenied => "permission denied",
97-
ErrorKind::ConnectionRefused => "connection refused",
98-
ErrorKind::ConnectionReset => "connection reset",
99-
ErrorKind::ConnectionAborted => "connection aborted",
100-
ErrorKind::NotConnected => "not connected",
101-
ErrorKind::AddrInUse => "address in use",
102-
ErrorKind::AddrNotAvailable => "address not available",
103-
ErrorKind::BrokenPipe => "broken pipe",
104-
ErrorKind::AlreadyExists => "entity already exists",
105-
ErrorKind::WouldBlock => "operation would block",
106-
ErrorKind::InvalidInput => "invalid input parameter",
107-
ErrorKind::InvalidData => "invalid data",
108-
ErrorKind::TimedOut => "timed out",
109-
ErrorKind::WriteZero => "write zero",
110-
ErrorKind::Interrupted => "operation interrupted",
111-
ErrorKind::Other => "other os error",
112-
ErrorKind::UnexpectedEof => "unexpected end of file",
113-
}
114-
}
115-
}
116-
11792
impl From<io::ErrorKind> for ErrorKind {
11893
fn from(kind: io::ErrorKind) -> Self {
11994
match kind {
@@ -140,10 +115,35 @@ impl From<io::ErrorKind> for ErrorKind {
140115
}
141116
}
142117

118+
impl From<ErrorKind> for io::Error {
119+
fn from(kind: ErrorKind) -> Self {
120+
let kind = match kind {
121+
ErrorKind::NotFound => io::ErrorKind::NotFound,
122+
ErrorKind::PermissionDenied => io::ErrorKind::PermissionDenied,
123+
ErrorKind::ConnectionRefused => io::ErrorKind::ConnectionRefused,
124+
ErrorKind::ConnectionReset => io::ErrorKind::ConnectionReset,
125+
ErrorKind::ConnectionAborted => io::ErrorKind::ConnectionAborted,
126+
ErrorKind::NotConnected => io::ErrorKind::NotConnected,
127+
ErrorKind::AddrInUse => io::ErrorKind::AddrInUse,
128+
ErrorKind::AddrNotAvailable => io::ErrorKind::AddrNotAvailable,
129+
ErrorKind::BrokenPipe => io::ErrorKind::BrokenPipe,
130+
ErrorKind::AlreadyExists => io::ErrorKind::AlreadyExists,
131+
ErrorKind::WouldBlock => io::ErrorKind::WouldBlock,
132+
ErrorKind::InvalidInput => io::ErrorKind::InvalidInput,
133+
ErrorKind::InvalidData => io::ErrorKind::InvalidData,
134+
ErrorKind::TimedOut => io::ErrorKind::TimedOut,
135+
ErrorKind::WriteZero => io::ErrorKind::WriteZero,
136+
ErrorKind::Interrupted => io::ErrorKind::Interrupted,
137+
ErrorKind::UnexpectedEof => io::ErrorKind::UnexpectedEof,
138+
ErrorKind::Other => io::ErrorKind::Other,
139+
};
140+
io::Error::from(kind)
141+
}
142+
}
143+
143144
/// Internal representation of the error state.
144145
#[derive(Debug)]
145146
enum Repr {
146-
Simple,
147147
Io(io::Error),
148148
Custom(anyhow::Error),
149149
}
@@ -223,7 +223,7 @@ impl Error {
223223
#[cfg(backtrace)]
224224
pub fn backtrace(&self) -> &std::backtrace::Backtrace {
225225
match self {
226-
Repr::Simple => std::backtrace::Backtrace::capture(),
226+
Repr::Io => std::backtrace::Backtrace::capture(),
227227
Repr::Custom(err) => err.backtrace(),
228228
}
229229
}
@@ -266,7 +266,6 @@ impl Error {
266266
impl Display for Error {
267267
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
268268
match &self.repr {
269-
Repr::Simple => write!(formatter, "{}", self.kind.as_str()),
270269
Repr::Io(io) => write!(formatter, "{}", io),
271270
Repr::Custom(err) => write!(formatter, "{}", err),
272271
}
@@ -276,7 +275,6 @@ impl Display for Error {
276275
impl Debug for Error {
277276
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
278277
match &self.repr {
279-
Repr::Simple => write!(formatter, "{}", self.kind.as_str()),
280278
Repr::Io(io) => write!(formatter, "{}", io),
281279
Repr::Custom(err) => write!(formatter, "{}", err),
282280
}
@@ -299,8 +297,8 @@ where
299297
impl From<ErrorKind> for Error {
300298
fn from(kind: ErrorKind) -> Self {
301299
Self {
302-
kind,
303-
repr: Repr::Simple,
300+
kind: kind.clone(),
301+
repr: Repr::Io(kind.into()),
304302
status: StatusCode::InternalServerError,
305303
}
306304
}
@@ -309,7 +307,6 @@ impl From<ErrorKind> for Error {
309307
impl AsRef<dyn StdError + Send + Sync> for Error {
310308
fn as_ref(&self) -> &(dyn StdError + Send + Sync + 'static) {
311309
match &self.repr {
312-
Repr::Simple => todo!(),
313310
Repr::Io(ref io) => io,
314311
Repr::Custom(ref err) => err.as_ref(),
315312
}
@@ -319,7 +316,6 @@ impl AsRef<dyn StdError + Send + Sync> for Error {
319316
impl AsRef<dyn StdError> for Error {
320317
fn as_ref(&self) -> &(dyn StdError + 'static) {
321318
match &self.repr {
322-
Repr::Simple => todo!(),
323319
Repr::Io(ref io) => io,
324320
Repr::Custom(ref err) => err.as_ref(),
325321
}
@@ -329,7 +325,6 @@ impl AsRef<dyn StdError> for Error {
329325
impl From<Error> for Box<dyn StdError + Send + Sync + 'static> {
330326
fn from(error: Error) -> Self {
331327
match error.repr {
332-
Repr::Simple => todo!(),
333328
Repr::Io(io) => io.into(),
334329
Repr::Custom(err) => err.into(),
335330
}

0 commit comments

Comments
 (0)