Trait ipnet::IpAdd
[−]
[src]
pub trait IpAdd<RHS = Self> { type Output; fn saturating_add(self, rhs: RHS) -> Self::Output; }
Provides a saturating_add()
method for Ipv4Addr
and Ipv6Addr
.
Panics
When attempting to add an IpAddr::V4
from an IpAddr::V6
and vice
versa.
Examples
use std::net::{Ipv4Addr, Ipv6Addr}; use std::str::FromStr; use ipnet::{IpAdd, Emu128}; 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("254.254.254.254").unwrap(); assert_eq!(ip1.saturating_add(ip0), Ipv4Addr::from_str("1.1.1.1").unwrap()); assert_eq!(ip1.saturating_add(ip1), Ipv4Addr::from_str("2.2.2.2").unwrap()); assert_eq!(u32::from(ip2.saturating_add(ip1)), u32::max_value()); assert_eq!(u32::from(ip2.saturating_add(ip2)), u32::max_value()); let ip60 = Ipv6Addr::from_str("::").unwrap(); let ip61 = Ipv6Addr::from_str("::1").unwrap(); let ip62 = Ipv6Addr::from_str("ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe").unwrap(); assert_eq!(ip61.saturating_add(ip60), Ipv6Addr::from_str("::1").unwrap()); assert_eq!(ip61.saturating_add(ip61), Ipv6Addr::from_str("::2").unwrap()); assert_eq!(Emu128::from(ip62.saturating_add(ip61)), Emu128::max_value()); assert_eq!(Emu128::from(ip62.saturating_add(ip62)), Emu128::max_value());
Associated Types
type Output
Required Methods
fn saturating_add(self, rhs: RHS) -> Self::Output
Implementors
impl IpAdd<u32> for IpAddr type Output = IpAddr;
impl IpAdd<IpAddr> for IpAddr type Output = IpAddr;
impl IpAdd<Ipv4Addr> for Ipv4Addr type Output = Ipv4Addr;
impl IpAdd<u32> for Ipv4Addr type Output = Ipv4Addr;
impl IpAdd<Ipv6Addr> for Ipv6Addr type Output = Ipv6Addr;
impl IpAdd<Emu128> for Ipv6Addr type Output = Ipv6Addr;
impl IpAdd<u32> for Ipv6Addr type Output = Ipv6Addr;