xref: /xiu/library/container/mpegts/src/errors.rs (revision ea7993e4)
1 use {
2     failure::Fail,
3     bytesio::bytes_errors::{BytesReadError, BytesWriteError},
4     std::io::Error,
5 };
6 
7 #[derive(Debug, Fail)]
8 pub enum MpegTsErrorValue {
9     #[fail(display = "bytes read error\n")]
10     BytesReadError(BytesReadError),
11 
12     #[fail(display = "bytes write error\n")]
13     BytesWriteError(BytesWriteError),
14 
15     #[fail(display = "io error\n")]
16     IOError(Error),
17 
18     #[fail(display = "program number exists\n")]
19     ProgramNumberExists,
20 
21     #[fail(display = "pmt count execeed\n")]
22     PmtCountExeceed,
23 
24     #[fail(display = "stream count execeed\n")]
25     StreamCountExeceed,
26 
27     #[fail(display = "stream not found\n")]
28     StreamNotFound,
29 }
30 #[derive(Debug)]
31 pub struct MpegTsError {
32     pub value: MpegTsErrorValue,
33 }
34 
35 impl From<BytesReadError> for MpegTsError {
36     fn from(error: BytesReadError) -> Self {
37         MpegTsError {
38             value: MpegTsErrorValue::BytesReadError(error),
39         }
40     }
41 }
42 
43 impl From<BytesWriteError> for MpegTsError {
44     fn from(error: BytesWriteError) -> Self {
45         MpegTsError {
46             value: MpegTsErrorValue::BytesWriteError(error),
47         }
48     }
49 }
50 
51 impl From<Error> for MpegTsError {
52     fn from(error: Error) -> Self {
53         MpegTsError {
54             value: MpegTsErrorValue::IOError(error),
55         }
56     }
57 }
58