Files
axum/src/error.rs
T

39 lines
803 B
Rust
Raw Normal View History

2021-08-07 19:56:44 +02:00
use std::{error::Error as StdError, fmt};
use tower::BoxError;
/// Errors that can happen when using axum.
#[derive(Debug)]
pub struct Error {
inner: BoxError,
}
impl Error {
pub(crate) fn new(error: impl Into<BoxError>) -> Self {
Self {
inner: error.into(),
}
}
2021-08-08 19:48:30 +02:00
pub(crate) fn downcast<T>(self) -> Result<T, Self>
where
T: StdError + 'static,
{
match self.inner.downcast::<T>() {
Ok(t) => Ok(*t),
Err(err) => Err(*err.downcast().unwrap()),
}
}
2021-08-07 19:56:44 +02:00
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.inner.fmt(f)
}
}
impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
Some(&*self.inner)
}
}