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`. Returned by [`ServiceDaemon`](crate::ServiceDaemon)
8 /// methods when the daemon's bounded command queue is temporarily full,
9 /// so the command could not be enqueued. The caller can retry after a
10 /// short delay.
11 Again,
12
13 /// The daemon thread has exited and its command channel is closed, so the
14 /// command could not be delivered. Returned by [`ServiceDaemon`](crate::ServiceDaemon)
15 /// methods after [`shutdown`](crate::ServiceDaemon::shutdown) has been
16 /// called or after the daemon thread has terminated for another reason.
17 /// Retrying will not help; callers should log and move on (or create a
18 /// new [`ServiceDaemon`](crate::ServiceDaemon)).
19 DaemonShutdown,
20
21 /// A generic error message.
22 Msg(String),
23
24 /// Error during parsing of ip address
25 ParseIpAddr(String),
26}
27
28impl fmt::Display for Error {
29 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30 match self {
31 Self::Msg(s) => write!(f, "{s}"),
32 Self::ParseIpAddr(s) => write!(f, "parsing of ip addr failed, reason: {s}"),
33 Self::Again => write!(f, "try again"),
34 Self::DaemonShutdown => write!(f, "daemon has shut down"),
35 }
36 }
37}
38
39impl std::error::Error for Error {}
40
41/// One and only `Result` type from this library crate.
42pub type Result<T> = core::result::Result<T, Error>;
43
44/// A simple macro to report all kinds of errors.
45macro_rules! e_fmt {
46 ($($arg:tt)+) => {
47 Error::Msg(format!($($arg)+))
48 };
49 }
50
51pub(crate) use e_fmt;