# 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`.

Subtracting an integer from an IP address returns the modified IP address. A `u32` may be subtracted from an IPv4 address and a `u128` may be subtracted from an IPv6 address.

Subtracting an IP address from another IP address of the same type returns an integer of the appropriate width. A `u32` for IPv4 and a `u128` for IPv6. Subtracting IP addresses is useful for getting the range between two IP addresses.

# Examples

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

    let min: Ipv4Addr = "0.0.0.0".parse().unwrap();
    let ip1: Ipv4Addr = "192.168.1.5".parse().unwrap();
    let ip2: Ipv4Addr = "192.168.1.100".parse().unwrap();

    assert_eq!(min.saturating_sub(ip1), 0);
    assert_eq!(ip2.saturating_sub(ip1), 95);
    assert_eq!(min.saturating_sub(5), min);
    assert_eq!(ip2.saturating_sub(95), ip1);

    let min: Ipv6Addr = "::".parse().unwrap();
    let ip1: Ipv6Addr = "fd00::5".parse().unwrap();
    let ip2: Ipv6Addr = "fd00::64".parse().unwrap();

    assert_eq!(min.saturating_sub(ip1), 0);
    assert_eq!(ip2.saturating_sub(ip1), 95);
    assert_eq!(min.saturating_sub(5u128), min);
    assert_eq!(ip2.saturating_sub(95u128), ip1);

## Associated Types

### `type Output` [src]

Loading content...

## Required methods

### `fn saturating_sub(self, rhs: RHS) -> Self::Output` [src]

Loading content...

## Implementations on Foreign Types

### `impl IpSub<Ipv4Addr> for Ipv4Addr` [src]

#### `type Output = u32`

#### `fn saturating_sub(self, rhs: Ipv4Addr) -> u32` [src]

### `impl IpSub<u32> for Ipv4Addr` [src]

#### `type Output = Ipv4Addr`

#### `fn saturating_sub(self, rhs: u32) -> Ipv4Addr` [src]

### `impl IpSub<Ipv6Addr> for Ipv6Addr` [src]

#### `type Output = u128`

#### `fn saturating_sub(self, rhs: Ipv6Addr) -> u128` [src]

### `impl IpSub<u128> for Ipv6Addr` [src]

#### `type Output = Ipv6Addr`

#### `fn saturating_sub(self, rhs: u128) -> Ipv6Addr` [src]

Loading content...

## Implementors

Loading content...