cidr_block 0.1.0

A library for CIDR block manipulation in Rust which provides utilities to parse, validate, and manipulate CIDR notation and get individual ip addresses.
Documentation
pub trait IPExt: Clone + Copy {
    type Error;
    type LenType;

    fn next_ip(&self, prefix_length: u8, n: Self::LenType) -> Result<Self, Self::Error>
    where
        Self: Sized;

    fn num_ips(block: &str) -> Result<Self::LenType, Self::Error>
    where
        Self: Sized;
}

impl IPExt for std::net::Ipv4Addr {
    type Error = super::Error;
    type LenType = u32;

    fn next_ip(&self, prefix_length: u8, n: u32) -> Result<Self, Self::Error> {
        super::next_ip_v4(*self, prefix_length, n)
    }

    fn num_ips(block: &str) -> Result<u32, Self::Error> {
        super::v4_num_ips(block)
    }
}

impl IPExt for std::net::Ipv6Addr {
    type Error = super::Error;
    type LenType = u128;

    fn next_ip(&self, prefix_length: u8, n: u128) -> Result<Self, Self::Error> {
        super::next_ip_v6(*self, prefix_length, n)
    }

    fn num_ips(block: &str) -> Result<u128, Self::Error> {
        super::v6_num_ips(block)
    }
}