service_binding/
lib.rs

1#![doc = include_str!("../README.md")]
2#![deny(missing_debug_implementations)]
3#![deny(missing_docs)]
4
5mod service;
6
7use std::io;
8use std::num::ParseIntError;
9
10pub use service::Binding;
11pub use service::Listener;
12pub use service::Stream;
13
14/// Errors while processing service listeners.
15#[derive(Debug)]
16#[non_exhaustive]
17pub enum Error {
18    /// Address cannot be parsed and did not resolve to a known domain
19    BadAddress(io::Error),
20
21    /// Descriptor value cannot be parsed to a number.
22    BadDescriptor(ParseIntError),
23
24    /// Descriptor value exceeds acceptable range.
25    DescriptorOutOfRange(i32),
26
27    /// Descriptor environment variable (`LISTEN_FDS`) is missing.
28    DescriptorsMissing,
29
30    /// Specified URI scheme is not supported.
31    UnsupportedScheme,
32}
33
34impl From<ParseIntError> for Error {
35    fn from(error: ParseIntError) -> Self {
36        Error::BadDescriptor(error)
37    }
38}
39
40impl std::fmt::Display for Error {
41    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42        write!(f, "{:?}", self)
43    }
44}
45
46impl std::error::Error for Error {}
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_display() {
54        format!("{}", Error::UnsupportedScheme);
55    }
56}