http_error/
any_http_error.rs

1use std::{error, fmt};
2
3use crate::HttpError;
4
5#[derive(Debug)]
6pub struct AnyHttpError(Box<dyn HttpError + Send + 'static>);
7
8impl fmt::Display for AnyHttpError {
9    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10        self.0.fmt(f)
11    }
12}
13
14impl error::Error for AnyHttpError {
15    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
16        self.0.source()
17    }
18}
19
20impl From<AnyHttpError> for Box<dyn HttpError + Send + 'static> {
21    fn from(err: AnyHttpError) -> Self {
22        err.0
23    }
24}
25
26impl<E> From<E> for AnyHttpError
27where
28    E: HttpError + Send + 'static,
29{
30    fn from(err: E) -> Self {
31        Self(Box::new(err))
32    }
33}
34
35impl From<Box<dyn HttpError + Send + 'static>> for AnyHttpError {
36    fn from(err: Box<dyn HttpError + Send + 'static>) -> Self {
37        Self(err)
38    }
39}