Skip to main content

local_ip_address/
error.rs

1use std::fmt;
2
3#[derive(Debug, PartialEq)]
4pub enum Error {
5    /// Returned when `local_ip` is unable to find the system's local IP address
6    /// in the collection of network interfaces
7    LocalIpAddressNotFound,
8    /// Returned when an error occurs in the strategy level.
9    /// The error message may include any internal strategy error if available
10    StrategyError(String),
11    /// Returned when the current platform is not yet supported
12    PlatformNotSupported(String),
13}
14
15impl fmt::Display for Error {
16    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17        match self {
18            Error::LocalIpAddressNotFound => write!(
19                f,
20                "The Local IP Address wasn't available in the network interfaces list/table"
21            ),
22            Error::StrategyError(msg) => write!(
23                f,
24                "An error occurred executing the underlying strategy error.\n{}",
25                msg
26            ),
27            Error::PlatformNotSupported(platform) => {
28                write!(f, "The current platform: `{}`, is not supported", platform)
29            }
30        }
31    }
32}
33
34impl std::error::Error for Error {}