mdns_sd/
error.rs

1use std::fmt;
2
3/// A basic error type from this library.
4#[derive(Clone, Debug, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum Error {
7    /// Like a classic EAGAIN. The receiver should retry.
8    Again,
9
10    /// A generic error message.
11    Msg(String),
12
13    /// Error during parsing of ip address
14    ParseIpAddr(String),
15}
16
17impl fmt::Display for Error {
18    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19        match self {
20            Self::Msg(s) => write!(f, "{}", s),
21            Self::ParseIpAddr(s) => write!(f, "parsing of ip addr failed, reason: {}", s),
22            Self::Again => write!(f, "try again"),
23        }
24    }
25}
26
27impl std::error::Error for Error {}
28
29/// One and only `Result` type from this library crate.
30pub type Result<T> = core::result::Result<T, Error>;
31
32/// A simple macro to report all kinds of errors.
33macro_rules! e_fmt {
34    ($($arg:tt)+) => {
35        Error::Msg(format!($($arg)+))
36    };
37  }
38
39pub(crate) use e_fmt;