Trait ipnet::IpBitAnd [] [src]

pub trait IpBitAnd<RHS = Self> {
    type Output;
    fn bitand(self, rhs: RHS) -> Self::Output;
}

Provides a bitand() method for Ipv4Addr and Ipv6Addr.

Examples

use std::net::{Ipv4Addr, Ipv6Addr};
use std::str::FromStr;
use ipnet::IpBitAnd;

let ip0 = Ipv4Addr::from_str("0.0.0.0").unwrap();
let ip1 = Ipv4Addr::from_str("1.1.1.1").unwrap();
let ip2 = Ipv4Addr::from_str("2.2.2.2").unwrap();

assert_eq!(ip0.bitand(ip1), Ipv4Addr::from_str("0.0.0.0").unwrap());
assert_eq!(ip1.bitand(ip1), Ipv4Addr::from_str("1.1.1.1").unwrap());
assert_eq!(ip1.bitand(ip2), Ipv4Addr::from_str("0.0.0.0").unwrap());
 
let ip60 = Ipv6Addr::from_str("::").unwrap();
let ip61 = Ipv6Addr::from_str("::1").unwrap();
let ip62 = Ipv6Addr::from_str("::2").unwrap();

assert_eq!(ip60.bitand(ip61), Ipv6Addr::from_str("::").unwrap());
assert_eq!(ip61.bitand(ip61), Ipv6Addr::from_str("::1").unwrap());
assert_eq!(ip61.bitand(ip62), Ipv6Addr::from_str("::").unwrap());

Associated Types

Required Methods

Implementors