[−][src]Function netaddr2::mask
pub fn mask<T, U>(addr: &T, mask: &T) -> T where
U: From<T>,
U: BitAnd<U, Output = U>,
T: From<U>,
T: Copy,
Mask the given referenced addr
with the given mask
, returning a new
IpAddr
.
Both addr
and mask
must be of the same enum
variant for the
operation to succeed.
Because this method is a generic, you will need to be sure to use type
annotations to specify which types it runs on. For Ipv4Addr
masking, you
should use ::<Ipv4Addr, u32>
and for Ipv6Addr
masking, the best choice
is ::<Ipv6Addr, u128>
. The Rust compiler will complain if you try to do
this with incompatible types.
Examples
let addr = Ipv4Addr::new(127, 0, 0, 1); let mask = Ipv4Addr::new(255, 0, 0, 0); assert_eq!(netaddr2::mask::<Ipv4Addr, u32>(&addr, &mask), Ipv4Addr::new(127, 0, 0, 0));