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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
pub use self::any::AnyIpCidr;

mod any;
mod combined;
mod direct;
mod from_str;
mod serde;

#[cfg(feature = "bitstring")]
#[cfg(test)]
mod bitstring_tests;
#[cfg(test)]
mod tests;

use std::net::{
	Ipv4Addr,
	Ipv6Addr,
};

/// [`Cidr`] type representing an IPv4 network
///
/// Ordering based on lexicographic bitstring representation.
///
/// [`Cidr`]: crate::Cidr
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct Ipv4Cidr {
	pub(crate) address: Ipv4Addr,
	pub(crate) network_length: u8,
}

/// [`Cidr`] type representing an IPv6 network
///
/// Ordering based on lexicographic bitstring representation.
///
/// [`Cidr`]: crate::Cidr
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct Ipv6Cidr {
	pub(crate) address: Ipv6Addr,
	pub(crate) network_length: u8,
}

/// [`Cidr`] type representing either an IPv4 or an IPv6 network
///
/// [`Cidr`]: crate::Cidr
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub enum IpCidr {
	/// IPv4 network
	V4(Ipv4Cidr),
	/// IPv6 network
	V6(Ipv6Cidr),
}