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.
Panics
When attempting to subtract an IpAddr::V4 from an IpAddr::V6 and
vice versa.
Examples
use std::net::{Ipv4Addr, Ipv6Addr}; use std::str::FromStr; use ipnet::IpSub; 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.saturating_sub(ip1), Ipv4Addr::from_str("0.0.0.0").unwrap()); assert_eq!(ip2.saturating_sub(ip1), Ipv4Addr::from_str("1.1.1.1").unwrap()); 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), Ipv6Addr::from_str("::").unwrap()); assert_eq!(ip62.saturating_sub(ip61), Ipv6Addr::from_str("::1").unwrap());
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<IpAddr> for IpAddr type Output = IpAddr;impl IpSub<Ipv4Addr> for Ipv4Addr type Output = Ipv4Addr;impl IpSub<u32> for Ipv4Addr type Output = Ipv4Addr;impl IpSub<Ipv6Addr> for Ipv6Addr type Output = Ipv6Addr;impl IpSub<Emu128> for Ipv6Addr type Output = Ipv6Addr;impl IpSub<u32> for Ipv6Addr type Output = Ipv6Addr;