Struct iprange::IpRange [] [src]

pub struct IpRange { /* fields omitted */ }

A set of subnets that supports various operations.

IntoIter is implemented for &IpRange. So, you can use for to iterate over the subnets in an IpRange:

use iprange::{IpRange, Subnet};

let ip_range: IpRange = ["172.16.0.0/16", "192.168.1.0/24"]
    .iter()
    .map(|s| s.parse::<Subnet>().unwrap())
    .collect();

for subnet in &ip_range {
    println!("{:?}", subnet);
}

Methods

impl IpRange
[src]

[src]

Creates an empty IpRange.

[src]

Add a subnet to self.

Returns &mut self in order to enable method chaining.

Pay attention that this operation will not combine two subnets automatically. To do this, call simplify method explicitly. For example:

use iprange::IpRange;

let mut ip_range = IpRange::new();
ip_range.add("192.168.0.0/24".parse().unwrap())
        .add("192.168.1.0/24".parse().unwrap());
assert_eq!(ip_range.into_iter().count(), 2);

ip_range.simplify();
assert_eq!(ip_range.into_iter().count(), 1);

[src]

Remove a subnet from self.

Returns &mut self in order to enable method chaining.

self does not necessarily has exactly the subnet to be removed. The subnet can be a subnet of a subnet in self. This method will do splitting and remove the corresponding subnet. For example:

use iprange::IpRange;

let mut ip_range = IpRange::new();
ip_range.add("192.168.0.0/23".parse().unwrap())
        .remove("192.168.0.0/24".parse().unwrap());
// Now, ip_range has only one subnet: "192.168.1.0/24".

[src]

Simplify self by combining subnets. For example:

use iprange::IpRange;

let mut ip_range = IpRange::new();
ip_range
    .add("192.168.0.0/20".parse().unwrap())
    .add("192.168.16.0/22".parse().unwrap())
    .add("192.168.20.0/24".parse().unwrap())
    .add("192.168.21.0/24".parse().unwrap())
    .add("192.168.22.0/24".parse().unwrap())
    .add("192.168.23.0/24".parse().unwrap())
    .add("192.168.24.0/21".parse().unwrap())
    .simplify();
// Now, ip_range has only one subnet: "192.168.0.0/19".

[src]

Returns a new IpRange which contains all subnets that is either in self or in other.

The returned IpRange is simplified.

[src]

Returns a new IpRange which contains all subnets that is in both self and other.

The returned IpRange is simplified.

[src]

Returns a new IpRange which contains all subnets that is in self while not in other.

The returned IpRange is simplified.

[src]

Tests if ip is in self.

[src]

Tests if self includes subnet.

[src]

Returns the subnet in self that contains ip.

Returns None if no subnet in self contains ip.

[src]

Returns the subnet in self which is the supernetwork of subnet.

Returns None if no subnet in self includes subnet.

Trait Implementations

impl Clone for IpRange
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for IpRange
[src]

[src]

Formats the value using the given formatter.

impl PartialEq for IpRange
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl Eq for IpRange
[src]

impl<'a> IntoIterator for &'a IpRange
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more

impl FromIterator<Subnet> for IpRange
[src]

[src]

Creates a value from an iterator. Read more

impl<'a> FromIterator<&'a Subnet> for IpRange
[src]

[src]

Creates a value from an iterator. Read more