pub enum IpNet {
V4 {
addr: Ipv4Addr,
prefix: u8,
},
V6 {
addr: Ipv6Addr,
prefix: u8,
},
}Available on crate feature
tower only.Expand description
An IP network: CIDR prefix membership without any new dependency.
Construct with IpNet::parse ("10.0.0.0/8", or a bare IP which
becomes /32 / /128) or the struct literals.
Variants§
V4
An IPv4 CIDR range.
Fields
§
addr: Ipv4AddrNetwork address. Host bits beyond prefix are ignored by
IpNet::contains.
V6
An IPv6 CIDR range.
Fields
§
addr: Ipv6AddrNetwork address. Host bits beyond prefix are ignored by
IpNet::contains.
Implementations§
Source§impl IpNet
impl IpNet
Sourcepub fn parse(s: &str) -> Result<Self, ClientIpError>
pub fn parse(s: &str) -> Result<Self, ClientIpError>
Parse "10.0.0.0/8", "2001:db8::/32", or a bare IP (implicit
/32 for IPv4, /128 for IPv6). A v4-mapped IPv6 address
(::ffff:10.0.0.1) is normalized to IPv4.
Sourcepub fn contains(&self, ip: IpAddr) -> bool
pub fn contains(&self, ip: IpAddr) -> bool
Exact CIDR membership at the prefix edge.
A v4-mapped IPv6 argument is evaluated as IPv4 (see module
docs), so it matches IPv4 networks only. Cross-family
membership is otherwise false.
Trait Implementations§
impl Copy for IpNet
impl Eq for IpNet
impl StructuralPartialEq for IpNet
Auto Trait Implementations§
impl Freeze for IpNet
impl RefUnwindSafe for IpNet
impl Send for IpNet
impl Sync for IpNet
impl Unpin for IpNet
impl UnsafeUnpin for IpNet
impl UnwindSafe for IpNet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more