use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum Error {
#[doc(hidden)]
#[deprecated(since = "0.10.0", note = "no longer produced")]
#[error("invalid procotol")]
InvalidProtocol,
#[error("internal error")]
InternalError,
#[doc(hidden)]
#[deprecated(since = "0.10.0", note = "malformed packets are silently dropped")]
#[error("Decode echo reply error occurred while processing the ICMP echo reply.")]
DecodeEchoReplyError,
#[error("io error: {error}")]
IoError {
#[from]
#[source]
error: ::std::io::Error,
},
#[error("ping request timed out")]
Timeout,
#[error("payload too large, the maximum is {max} bytes")]
PayloadTooLarge {
max: usize,
},
}
pub(crate) fn io_error(error: ::std::io::Error) -> Error {
match error.kind() {
::std::io::ErrorKind::TimedOut | ::std::io::ErrorKind::WouldBlock => Error::Timeout,
_ => Error::IoError { error },
}
}