File
Blob: firmware/vendor/str0m/src/io/error.rs
| 1 | use std::error::Error; |
| 2 | use std::fmt; |
| 3 | use std::io; |
| 4 | |
| 5 | pub use is::StunError; |
| 6 | |
| 7 | /// Errors from parsing network data. |
| 8 | #[derive(Debug)] |
| 9 | pub enum NetError { |
| 10 | /// Some STUN protocol error. |
| 11 | Stun(StunError), |
| 12 | |
| 13 | /// A wrapped IO error. |
| 14 | Io(io::Error), |
| 15 | } |
| 16 | |
| 17 | impl fmt::Display for NetError { |
| 18 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 19 | match self { |
| 20 | NetError::Stun(err) => write!(f, "{}", err), |
| 21 | NetError::Io(err) => write!(f, "{}", err), |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | impl Error for NetError { |
| 27 | fn source(&self) -> Option<&(dyn Error + 'static)> { |
| 28 | match self { |
| 29 | NetError::Stun(err) => Some(err), |
| 30 | NetError::Io(err) => Some(err), |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | impl From<StunError> for NetError { |
| 36 | fn from(err: StunError) -> Self { |
| 37 | NetError::Stun(err) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | impl From<io::Error> for NetError { |
| 42 | fn from(err: io::Error) -> Self { |
| 43 | NetError::Io(err) |
| 44 | } |
| 45 | } |