xref: /xiu/protocol/rtmp/src/netconnection/errors.rs (revision ea7993e4)
1 use {
2     crate::amf0::errors::{Amf0ReadError, Amf0WriteError},
3     failure::{Backtrace, Fail},
4     std::fmt,
5 };
6 
7 #[derive(Debug)]
8 pub struct NetConnectionError {
9     pub value: NetConnectionErrorValue,
10 }
11 #[derive(Debug, Fail)]
12 pub enum NetConnectionErrorValue {
13     #[fail(display = "amf0 write error: {}\n", _0)]
14     Amf0WriteError(Amf0WriteError),
15     #[fail(display = "amf0 read error: {}\n", _0)]
16     Amf0ReadError(Amf0ReadError),
17 }
18 
19 impl From<Amf0WriteError> for NetConnectionError {
20     fn from(error: Amf0WriteError) -> Self {
21         NetConnectionError {
22             value: NetConnectionErrorValue::Amf0WriteError(error),
23         }
24     }
25 }
26 
27 impl From<Amf0ReadError> for NetConnectionError {
28     fn from(error: Amf0ReadError) -> Self {
29         NetConnectionError {
30             value: NetConnectionErrorValue::Amf0ReadError(error),
31         }
32     }
33 }
34 
35 impl fmt::Display for NetConnectionError {
36     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
37         fmt::Display::fmt(&self.value, f)
38     }
39 }
40 
41 impl Fail for NetConnectionError {
42     fn cause(&self) -> Option<&dyn Fail> {
43         self.value.cause()
44     }
45 
46     fn backtrace(&self) -> Option<&Backtrace> {
47         self.value.backtrace()
48     }
49 }
50