1 use { 2 bytesio::bytes_errors::{BytesReadError, BytesWriteError}, 3 failure::{Backtrace, Fail}, 4 std::fmt, 5 std::io::Error, 6 }; 7 8 #[derive(Debug, Fail)] 9 pub enum MpegTsErrorValue { 10 #[fail(display = "bytes read error")] 11 BytesReadError(BytesReadError), 12 13 #[fail(display = "bytes write error")] 14 BytesWriteError(BytesWriteError), 15 16 #[fail(display = "io error")] 17 IOError(Error), 18 19 #[fail(display = "program number exists")] 20 ProgramNumberExists, 21 22 #[fail(display = "pmt count execeed")] 23 PmtCountExeceed, 24 25 #[fail(display = "stream count execeed")] 26 StreamCountExeceed, 27 28 #[fail(display = "stream not found")] 29 StreamNotFound, 30 } 31 #[derive(Debug)] 32 pub struct MpegTsError { 33 pub value: MpegTsErrorValue, 34 } 35 36 impl From<BytesReadError> for MpegTsError { from(error: BytesReadError) -> Self37 fn from(error: BytesReadError) -> Self { 38 MpegTsError { 39 value: MpegTsErrorValue::BytesReadError(error), 40 } 41 } 42 } 43 44 impl From<BytesWriteError> for MpegTsError { from(error: BytesWriteError) -> Self45 fn from(error: BytesWriteError) -> Self { 46 MpegTsError { 47 value: MpegTsErrorValue::BytesWriteError(error), 48 } 49 } 50 } 51 52 impl From<Error> for MpegTsError { from(error: Error) -> Self53 fn from(error: Error) -> Self { 54 MpegTsError { 55 value: MpegTsErrorValue::IOError(error), 56 } 57 } 58 } 59 60 impl fmt::Display for MpegTsError { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result61 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 62 fmt::Display::fmt(&self.value, f) 63 } 64 } 65 66 impl Fail for MpegTsError { cause(&self) -> Option<&dyn Fail>67 fn cause(&self) -> Option<&dyn Fail> { 68 self.value.cause() 69 } 70 backtrace(&self) -> Option<&Backtrace>71 fn backtrace(&self) -> Option<&Backtrace> { 72 self.value.backtrace() 73 } 74 } 75