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