pub trait IpAdd<RHS = Self> {
    type Output;
    fn saturating_add(self, rhs: RHS) -> Self::Output;
}
Expand description

Provides a saturating_add() method for Ipv4Addr and Ipv6Addr.

Adding an integer to an IP address returns the modified IP address. A u32 may added to an IPv4 address and a u128 may be added to an IPv6 address.

Examples

use std::net::{Ipv4Addr, Ipv6Addr};
use ipnet::IpAdd;

let ip0: Ipv4Addr = "192.168.0.0".parse().unwrap();
let ip1: Ipv4Addr = "192.168.0.5".parse().unwrap();
let ip2: Ipv4Addr = "255.255.255.254".parse().unwrap();
let max: Ipv4Addr = "255.255.255.255".parse().unwrap();

assert_eq!(ip0.saturating_add(5), ip1);
assert_eq!(ip2.saturating_add(1), max);
assert_eq!(ip2.saturating_add(5), max);

let ip0: Ipv6Addr = "fd00::".parse().unwrap();
let ip1: Ipv6Addr = "fd00::5".parse().unwrap();
let ip2: Ipv6Addr = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe".parse().unwrap();
let max: Ipv6Addr = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff".parse().unwrap();

assert_eq!(ip0.saturating_add(5), ip1);
assert_eq!(ip2.saturating_add(1), max);
assert_eq!(ip2.saturating_add(5), max);

Associated Types

Required methods

Implementations on Foreign Types

Implementors