Mercurial > crates > systemd-socket
diff src/error.rs @ 13:f740dadd2948
Added enable_systemd feature
This feature makes systemd support optional, on by default. While it may
seem strange that this feature exists, it makes sense for authors of
applications who want to make systemd optional. Thanks to this feature
the interface stays the same, it just fails to parse `systemd://`
addresses with a helpful error message.
author | Martin Habovstiak <martin.habovstiak@gmail.com> |
---|---|
date | Thu, 03 Dec 2020 16:34:09 +0100 |
parents | a7893294e9b2 |
children | bc76507dd878 |
line wrap: on
line diff
--- a/src/error.rs Sun Nov 29 14:15:33 2020 +0100 +++ b/src/error.rs Thu Dec 03 16:34:09 2020 +0100 @@ -19,14 +19,15 @@ pub(crate) enum ParseErrorInner { #[error("failed to parse socket address")] ResolvAddr(#[from] crate::resolv_addr::ResolvAddrError), - #[cfg(linux)] + #[cfg(all(linux, feature = "enable_systemd"))] #[error("invalid character '{c}' in systemd socket name {string} at position {pos}")] InvalidCharacter { string: String, c: char, pos: usize, }, - #[cfg(linux)] + #[cfg(all(linux, feature = "enable_systemd"))] #[error("systemd socket name {string} is {len} characters long which is more than the limit 255")] LongSocketName { string: String, len: usize, }, - #[cfg(not(linux))] - #[error("can't parse {0} because systemd is not supported on this operating system")] + #[cfg(not(all(linux, feature = "enable_systemd")))] + #[cfg_attr(not(linux), error("can't parse {0} because systemd is not supported on this operating system"))] + #[cfg_attr(linux, error("can't parse {0} because systemd support was disabled during build"))] SystemdUnsupported(String), } @@ -65,14 +66,14 @@ BindFailed { addr: std::net::SocketAddr, #[source] error: io::Error, }, #[error("failed to bind {addr}")] BindOrResolvFailed { addr: crate::resolv_addr::ResolvAddr, #[source] error: io::Error, }, - #[cfg(linux)] + #[cfg(all(linux, feature = "enable_systemd"))] #[error("failed to receive descriptors with names")] ReceiveDescriptors(#[source] crate::systemd_sockets::Error), #[error("missing systemd socket {0} - a typo or an attempt to bind twice")] - #[cfg(linux)] + #[cfg(all(linux, feature = "enable_systemd"))] MissingDescriptor(String), #[error("the systemd socket {0} is not an internet socket")] - #[cfg(linux)] + #[cfg(all(linux, feature = "enable_systemd"))] NotInetSocket(String), }