1use std::fmt;
2
3use actix_codec::{Decoder, Encoder};
4
5pub enum ServiceError<E, U: Encoder + Decoder> {
7 Service(E),
9 Encoder(<U as Encoder>::Error),
11 Decoder(<U as Decoder>::Error),
13}
14
15impl<E, U: Encoder + Decoder> From<E> for ServiceError<E, U> {
16 fn from(err: E) -> Self {
17 ServiceError::Service(err)
18 }
19}
20
21impl<E, U: Encoder + Decoder> fmt::Debug for ServiceError<E, U>
22where
23 E: fmt::Debug,
24 <U as Encoder>::Error: fmt::Debug,
25 <U as Decoder>::Error: fmt::Debug,
26{
27 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
28 match *self {
29 ServiceError::Service(ref e) => write!(fmt, "ServiceError::Service({:?})", e),
30 ServiceError::Encoder(ref e) => write!(fmt, "ServiceError::Encoder({:?})", e),
31 ServiceError::Decoder(ref e) => write!(fmt, "ServiceError::Encoder({:?})", e),
32 }
33 }
34}
35
36impl<E, U: Encoder + Decoder> fmt::Display for ServiceError<E, U>
37where
38 E: fmt::Display,
39 <U as Encoder>::Error: fmt::Debug,
40 <U as Decoder>::Error: fmt::Debug,
41{
42 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
43 match *self {
44 ServiceError::Service(ref e) => write!(fmt, "{}", e),
45 ServiceError::Encoder(ref e) => write!(fmt, "{:?}", e),
46 ServiceError::Decoder(ref e) => write!(fmt, "{:?}", e),
47 }
48 }
49}