rama::net::stream::dep::ipnet

Trait IpBitAnd

source
pub trait IpBitAnd<RHS = Self> {
    type Output;

    // Required method
    fn bitand(self, rhs: RHS) -> Self::Output;
}
Expand description

Provides a bitand() method for Ipv4Addr and Ipv6Addr.

§Examples

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

let ip: Ipv4Addr = "192.168.1.1".parse().unwrap();
let mask: Ipv4Addr = "255.255.0.0".parse().unwrap();
let res: Ipv4Addr = "192.168.0.0".parse().unwrap();

assert_eq!(ip.bitand(mask), res);
assert_eq!(ip.bitand(0xffff0000), res);
 
let ip: Ipv6Addr = "fd00:1234::1".parse().unwrap();
let mask: Ipv6Addr = "ffff::".parse().unwrap();
let res: Ipv6Addr = "fd00::".parse().unwrap();

assert_eq!(ip.bitand(mask), res);
assert_eq!(ip.bitand(0xffff_0000_0000_0000_0000_0000_0000_0000u128), res);

Required Associated Types§

Required Methods§

source

fn bitand(self, rhs: RHS) -> Self::Output

Implementations on Foreign Types§

source§

impl IpBitAnd for Ipv4Addr

source§

impl IpBitAnd for Ipv6Addr

source§

impl IpBitAnd<u32> for Ipv4Addr

source§

impl IpBitAnd<u128> for Ipv6Addr

Implementors§