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; 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());