1use ipnetwork::IpNetworkError;
2use std::{error, fmt};
3
4#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
6#[non_exhaustive]
7pub enum Error {
8 InvalidIpNetwork(String),
15 PrefixTooBig(crate::IpNetwork),
17}
18
19impl error::Error for Error {}
20
21impl fmt::Display for Error {
22 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
23 match self {
24 Error::InvalidIpNetwork(error) => write!(f, "{}", error),
25 Error::PrefixTooBig(crate::IpNetwork(net)) => write!(
26 f,
27 "{}/{} is already a full IP address",
28 net.ip(),
29 net.prefix()
30 ),
31 }
32 }
33}
34
35impl From<IpNetworkError> for Error {
36 fn from(error: IpNetworkError) -> Self {
37 Self::InvalidIpNetwork(error.to_string())
38 }
39}