axum_core/
error.rs

1use crate::BoxError;
2use std::{error::Error as StdError, fmt};
3
4/// Errors that can happen when using axum.
5#[derive(Debug)]
6pub struct Error {
7    inner: BoxError,
8}
9
10impl Error {
11    /// Create a new `Error` from a boxable error.
12    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.
19    pub fn into_inner(self) -> BoxError {
20        self.inner
21    }
22}
23
24impl fmt::Display for Error {
25    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26        self.inner.fmt(f)
27    }
28}
29
30impl StdError for Error {
31    fn source(&self) -> Option<&(dyn StdError + 'static)> {
32        Some(&*self.inner)
33    }
34}