netconfig_rs/
error.rs

1use std::error::Error as StdError;
2use std::io;
3use thiserror::Error as ThisError;
4
5#[non_exhaustive]
6#[derive(Debug, ThisError)]
7pub enum Error {
8    #[error("invalid parameter")]
9    InvalidParameter,
10    #[error("unexpected metadata")]
11    UnexpectedMetadata,
12    #[error("interface not found")]
13    InterfaceNotFound,
14    #[error("unknown error: {0}")]
15    Unknown(Box<dyn StdError>),
16    #[error("I/O error: {0}")]
17    Io(io::Error),
18}
19
20#[cfg(unix)]
21impl From<nix::Error> for Error {
22    fn from(e: nix::Error) -> Self {
23        Error::Unknown(Box::new(e))
24    }
25}
26
27#[cfg(windows)]
28impl From<windows::core::Error> for Error {
29    fn from(e: windows::core::Error) -> Self {
30        Self::Unknown(Box::new(e))
31    }
32}
33
34impl From<io::Error> for Error {
35    fn from(e: io::Error) -> Self {
36        Self::Io(e)
37    }
38}
39
40#[cfg(windows)]
41impl From<widestring::error::Utf16Error> for Error {
42    fn from(_: widestring::error::Utf16Error) -> Self {
43        Self::UnexpectedMetadata
44    }
45}
46
47impl From<Error> for io::Error {
48    fn from(value: Error) -> Self {
49        match value {
50            Error::Io(e) => e,
51            e => io::Error::other(format!("{:?}", e)),
52        }
53    }
54}