1 use { 2 crate::{ 3 amf0::errors::{Amf0ReadError, Amf0WriteError}, 4 chunk::errors::PackError, 5 }, 6 failure::{Backtrace, Fail}, 7 std::fmt, 8 }; 9 10 #[derive(Debug)] 11 pub struct NetConnectionError { 12 pub value: NetConnectionErrorValue, 13 } 14 #[derive(Debug, Fail)] 15 pub enum NetConnectionErrorValue { 16 #[fail(display = "amf0 write error: {}", _0)] 17 Amf0WriteError(Amf0WriteError), 18 #[fail(display = "amf0 read error: {}", _0)] 19 Amf0ReadError(Amf0ReadError), 20 #[fail(display = "pack error")] 21 PackError(PackError), 22 } 23 24 impl From<Amf0WriteError> for NetConnectionError { from(error: Amf0WriteError) -> Self25 fn from(error: Amf0WriteError) -> Self { 26 NetConnectionError { 27 value: NetConnectionErrorValue::Amf0WriteError(error), 28 } 29 } 30 } 31 32 impl From<Amf0ReadError> for NetConnectionError { from(error: Amf0ReadError) -> Self33 fn from(error: Amf0ReadError) -> Self { 34 NetConnectionError { 35 value: NetConnectionErrorValue::Amf0ReadError(error), 36 } 37 } 38 } 39 40 impl From<PackError> for NetConnectionError { from(error: PackError) -> Self41 fn from(error: PackError) -> Self { 42 NetConnectionError { 43 value: NetConnectionErrorValue::PackError(error), 44 } 45 } 46 } 47 48 impl fmt::Display for NetConnectionError { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result49 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 50 fmt::Display::fmt(&self.value, f) 51 } 52 } 53 54 impl Fail for NetConnectionError { cause(&self) -> Option<&dyn Fail>55 fn cause(&self) -> Option<&dyn Fail> { 56 self.value.cause() 57 } 58 backtrace(&self) -> Option<&Backtrace>59 fn backtrace(&self) -> Option<&Backtrace> { 60 self.value.backtrace() 61 } 62 } 63