use core::{self, fmt};
use std::error::Error as StdError;
use std::io;
#[derive(Debug)]
pub enum Error {
Exhausted,
Truncated,
Unrecognized,
Malformed,
MalformedNlaValue,
Io(io::Error),
#[doc(hidden)]
__Nonexhaustive,
}
pub type Result<T> = core::result::Result<T, Error>;
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.description())
}
}
impl StdError for Error {
fn description(&self) -> &str {
match *self {
Error::Exhausted => "buffer space exhausted",
Error::Truncated => "truncated packet",
Error::Unrecognized => "unrecognized packet",
Error::Malformed => "malformed packet",
Error::MalformedNlaValue => "failed to parse a netlink nla value",
Error::Io(_) => "failed to read or write a packet due to an IO error",
Error::__Nonexhaustive => unreachable!(),
}
}
fn cause(&self) -> Option<&StdError> {
None
}
}
impl From<io::Error> for Error {
fn from(io_err: io::Error) -> Error {
Error::Io(io_err)
}
}