Mercurial > crates > systemd-socket
comparison src/error.rs @ 6:a7893294e9b2
Make the crate compilable on non-linux systems
This makes the crate compile on other operating systems. Since systemd
is only supported on Linux, it simply disables systemd features on other
systems. The API is still the same, just parsing `systemd://` string
will return an error.
author | Martin Habovstiak <martin.habovstiak@gmail.com> |
---|---|
date | Fri, 27 Nov 2020 16:15:57 +0100 |
parents | 66c0e10c89fc |
children | f740dadd2948 |
comparison
equal
deleted
inserted
replaced
5:27456533853e | 6:a7893294e9b2 |
---|---|
17 | 17 |
18 #[derive(Debug, Error)] | 18 #[derive(Debug, Error)] |
19 pub(crate) enum ParseErrorInner { | 19 pub(crate) enum ParseErrorInner { |
20 #[error("failed to parse socket address")] | 20 #[error("failed to parse socket address")] |
21 ResolvAddr(#[from] crate::resolv_addr::ResolvAddrError), | 21 ResolvAddr(#[from] crate::resolv_addr::ResolvAddrError), |
22 #[cfg(linux)] | |
22 #[error("invalid character '{c}' in systemd socket name {string} at position {pos}")] | 23 #[error("invalid character '{c}' in systemd socket name {string} at position {pos}")] |
23 InvalidCharacter { string: String, c: char, pos: usize, }, | 24 InvalidCharacter { string: String, c: char, pos: usize, }, |
25 #[cfg(linux)] | |
24 #[error("systemd socket name {string} is {len} characters long which is more than the limit 255")] | 26 #[error("systemd socket name {string} is {len} characters long which is more than the limit 255")] |
25 LongSocketName { string: String, len: usize, }, | 27 LongSocketName { string: String, len: usize, }, |
28 #[cfg(not(linux))] | |
29 #[error("can't parse {0} because systemd is not supported on this operating system")] | |
30 SystemdUnsupported(String), | |
26 } | 31 } |
27 | 32 |
28 /// Error that can occur during parsing of `SocketAddr` from a `OsStr`/`OsString` | 33 /// Error that can occur during parsing of `SocketAddr` from a `OsStr`/`OsString` |
29 /// | 34 /// |
30 /// As opposed to parsing from `&str` or `String`, parsing from `OsStr` can fail due to one more | 35 /// As opposed to parsing from `&str` or `String`, parsing from `OsStr` can fail due to one more |
58 pub(crate) enum BindErrorInner { | 63 pub(crate) enum BindErrorInner { |
59 #[error("failed to bind {addr}")] | 64 #[error("failed to bind {addr}")] |
60 BindFailed { addr: std::net::SocketAddr, #[source] error: io::Error, }, | 65 BindFailed { addr: std::net::SocketAddr, #[source] error: io::Error, }, |
61 #[error("failed to bind {addr}")] | 66 #[error("failed to bind {addr}")] |
62 BindOrResolvFailed { addr: crate::resolv_addr::ResolvAddr, #[source] error: io::Error, }, | 67 BindOrResolvFailed { addr: crate::resolv_addr::ResolvAddr, #[source] error: io::Error, }, |
68 #[cfg(linux)] | |
63 #[error("failed to receive descriptors with names")] | 69 #[error("failed to receive descriptors with names")] |
64 ReceiveDescriptors(#[source] crate::systemd_sockets::Error), | 70 ReceiveDescriptors(#[source] crate::systemd_sockets::Error), |
65 #[error("missing systemd socket {0} - a typo or an attempt to bind twice")] | 71 #[error("missing systemd socket {0} - a typo or an attempt to bind twice")] |
72 #[cfg(linux)] | |
66 MissingDescriptor(String), | 73 MissingDescriptor(String), |
67 #[error("the systemd socket {0} is not an internet socket")] | 74 #[error("the systemd socket {0} is not an internet socket")] |
75 #[cfg(linux)] | |
68 NotInetSocket(String), | 76 NotInetSocket(String), |
69 } | 77 } |
70 | 78 |
71 /// Error that can happen when binding Tokio socket. | 79 /// Error that can happen when binding Tokio socket. |
72 /// | 80 /// |