• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use crate::BoxError;
2 use std::{error::Error as StdError, fmt};
3 
4 /// Errors that can happen when using axum.
5 #[derive(Debug)]
6 pub struct Error {
7     inner: BoxError,
8 }
9 
10 impl Error {
11     /// Create a new `Error` from a boxable error.
new(error: impl Into<BoxError>) -> Self12     pub fn new(error: impl Into<BoxError>) -> Self {
13         Self {
14             inner: error.into(),
15         }
16     }
17 
18     /// Convert an `Error` back into the underlying boxed trait object.
into_inner(self) -> BoxError19     pub fn into_inner(self) -> BoxError {
20         self.inner
21     }
22 }
23 
24 impl fmt::Display for Error {
fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result25     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26         self.inner.fmt(f)
27     }
28 }
29 
30 impl StdError for Error {
source(&self) -> Option<&(dyn StdError + 'static)>31     fn source(&self) -> Option<&(dyn StdError + 'static)> {
32         Some(&*self.inner)
33     }
34 }
35