1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use std::{
    error::Error,
    fmt::{self, Display, Formatter},
};

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
/// Possible errors of `Ipv6Cidr`.
pub enum Ipv6CidrError {
    IncorrectBitsRange,
    IncorrectMask,
    IncorrectIpv6CIDRString,
}

impl Display for Ipv6CidrError {
    #[inline]
    fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> {
        match self {
            Ipv6CidrError::IncorrectBitsRange => {
                f.write_str("The subnet size (bits) is out of range.")
            },
            Ipv6CidrError::IncorrectMask => f.write_str("The mask is incorrect."),
            Ipv6CidrError::IncorrectIpv6CIDRString => {
                f.write_str("The CIDR (IPv6) string is incorrect.")
            },
        }
    }
}

impl Error for Ipv6CidrError {}