Trait ipnet::IpSub
[−]
[src]
pub trait IpSub<RHS = Self> { type Output; fn saturating_sub(self, rhs: RHS) -> Self::Output; }
Provides a saturating_sub()
method for Ipv4Addr
and Ipv6Addr
.
Examples
use std::net::{Ipv4Addr, Ipv6Addr}; use std::str::FromStr; use ipnet::{IpSub, Emu128}; let ip0 = Ipv4Addr::from_str("0.0.0.0").unwrap(); let ip1 = Ipv4Addr::from_str("0.0.0.1").unwrap(); let ip2 = Ipv4Addr::from_str("0.0.0.2").unwrap(); assert_eq!(ip0.saturating_sub(ip1), 0); assert_eq!(ip2.saturating_sub(ip1), 1); assert_eq!(ip0.saturating_sub(1u32), ip0); assert_eq!(ip2.saturating_sub(1u32), ip1); let ip60 = Ipv6Addr::from_str("::").unwrap(); let ip61 = Ipv6Addr::from_str("::1").unwrap(); let ip62 = Ipv6Addr::from_str("::2").unwrap(); assert_eq!(ip60.saturating_sub(ip61), Emu128::from(0)); assert_eq!(ip62.saturating_sub(ip61), Emu128::from(1)); assert_eq!(ip60.saturating_sub(1u32), ip60); assert_eq!(ip62.saturating_sub(1u32), ip61);
Associated Types
type Output
Required Methods
fn saturating_sub(self, rhs: RHS) -> Self::Output
Implementors
impl IpSub<u32> for IpAddr type Output = IpAddr;
impl IpSub<Ipv4Addr> for Ipv4Addr type Output = u32;
impl IpSub<u32> for Ipv4Addr type Output = Ipv4Addr;
impl IpSub<Ipv6Addr> for Ipv6Addr type Output = Emu128;
impl IpSub<Emu128> for Ipv6Addr type Output = Ipv6Addr;
impl IpSub<u32> for Ipv6Addr type Output = Ipv6Addr;