1 use { 2 failure::Fail, 3 std::{fmt, io::Error}, 4 tokio::sync::broadcast::error::RecvError, 5 }; 6 7 #[derive(Debug)] 8 pub struct ClientError { 9 pub value: PushClientErrorValue, 10 } 11 12 impl fmt::Display for ClientError { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result13 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 14 fmt::Display::fmt(&self.value, f) 15 } 16 } 17 18 #[derive(Debug, Fail)] 19 pub enum PushClientErrorValue { 20 #[fail(display = "receive error")] 21 ReceiveError(RecvError), 22 23 #[fail(display = "send error")] 24 SendError, 25 #[fail(display = "io error")] 26 IOError(Error), 27 } 28 29 impl From<Error> for ClientError { from(error: Error) -> Self30 fn from(error: Error) -> Self { 31 ClientError { 32 value: PushClientErrorValue::IOError(error), 33 } 34 } 35 } 36 37 impl From<RecvError> for ClientError { from(error: RecvError) -> Self38 fn from(error: RecvError) -> Self { 39 ClientError { 40 value: PushClientErrorValue::ReceiveError(error), 41 } 42 } 43 } 44