14435d79dSHarlanC use { 24435d79dSHarlanC crate::amf0::errors::Amf0WriteError, 34435d79dSHarlanC failure::{Backtrace, Fail}, 488325f54SHarlanC bytesio::bytes_errors::{BytesReadError, BytesWriteError}, 54435d79dSHarlanC std::fmt, 64435d79dSHarlanC }; 7c2f3fbfaSHarlanC 8c2f3fbfaSHarlanC #[derive(Debug)] 908c16cccSHarlanC pub struct EventMessagesError { 1008c16cccSHarlanC pub value: EventMessagesErrorValue, 1108c16cccSHarlanC } 1208c16cccSHarlanC 13c2f3fbfaSHarlanC #[derive(Debug, Fail)] 1408c16cccSHarlanC pub enum EventMessagesErrorValue { 15*69de9bbdSHarlanC #[fail(display = "amf0 write error: {}", _0)] 1608c16cccSHarlanC Amf0WriteError(Amf0WriteError), 17*69de9bbdSHarlanC #[fail(display = "bytes write error: {}", _0)] 184ff0d3acSHarlanC BytesWriteError(BytesWriteError), 19*69de9bbdSHarlanC #[fail(display = "bytes read error: {}", _0)] 2097f0b5afSHarlanC BytesReadError(BytesReadError), 2197f0b5afSHarlanC #[fail(display = "unknow event message type")] 2297f0b5afSHarlanC UnknowEventMessageType, 2308c16cccSHarlanC } 2408c16cccSHarlanC 2508c16cccSHarlanC impl From<Amf0WriteError> for EventMessagesError { from(error: Amf0WriteError) -> Self2608c16cccSHarlanC fn from(error: Amf0WriteError) -> Self { 2708c16cccSHarlanC EventMessagesError { 2808c16cccSHarlanC value: EventMessagesErrorValue::Amf0WriteError(error), 2908c16cccSHarlanC } 3008c16cccSHarlanC } 3108c16cccSHarlanC } 3208c16cccSHarlanC 334ff0d3acSHarlanC impl From<BytesWriteError> for EventMessagesError { from(error: BytesWriteError) -> Self344ff0d3acSHarlanC fn from(error: BytesWriteError) -> Self { 3508c16cccSHarlanC EventMessagesError { 364ff0d3acSHarlanC value: EventMessagesErrorValue::BytesWriteError(error), 3708c16cccSHarlanC } 3808c16cccSHarlanC } 3908c16cccSHarlanC } 40c2f3fbfaSHarlanC 4197f0b5afSHarlanC impl From<BytesReadError> for EventMessagesError { from(error: BytesReadError) -> Self4297f0b5afSHarlanC fn from(error: BytesReadError) -> Self { 4397f0b5afSHarlanC EventMessagesError { 4497f0b5afSHarlanC value: EventMessagesErrorValue::BytesReadError(error), 4597f0b5afSHarlanC } 4697f0b5afSHarlanC } 4797f0b5afSHarlanC } 4897f0b5afSHarlanC 49c2f3fbfaSHarlanC impl fmt::Display for EventMessagesError { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result50c2f3fbfaSHarlanC fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 51c2f3fbfaSHarlanC fmt::Display::fmt(&self.value, f) 52c2f3fbfaSHarlanC } 53c2f3fbfaSHarlanC } 54c2f3fbfaSHarlanC 55c2f3fbfaSHarlanC impl Fail for EventMessagesError { cause(&self) -> Option<&dyn Fail>56c2f3fbfaSHarlanC fn cause(&self) -> Option<&dyn Fail> { 57c2f3fbfaSHarlanC self.value.cause() 58c2f3fbfaSHarlanC } 59c2f3fbfaSHarlanC backtrace(&self) -> Option<&Backtrace>60c2f3fbfaSHarlanC fn backtrace(&self) -> Option<&Backtrace> { 61c2f3fbfaSHarlanC self.value.backtrace() 62c2f3fbfaSHarlanC } 63c2f3fbfaSHarlanC } 64