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