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]
fn new() -> IpRange[src]
Creates an empty IpRange.
fn add(&mut self, subnet: Subnet) -> &mut 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);
fn remove(&mut self, subnet: Subnet) -> &mut IpRange[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".
fn simplify(&mut self)[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".
fn merge(&self, other: &IpRange) -> IpRange[src]
Returns a new IpRange which contains all subnets
that is either in self or in other.
The returned IpRange is simplified.
fn intersect(&self, other: &IpRange) -> IpRange[src]
Returns a new IpRange which contains all subnets
that is in both self and other.
The returned IpRange is simplified.
fn exclude(&self, other: &IpRange) -> IpRange[src]
Returns a new IpRange which contains all subnets
that is in self while not in other.
The returned IpRange is simplified.
fn contains<T: Into<CompactIpv4>>(&self, ip: T) -> bool[src]
Tests if ip is in self.
fn includes(&self, subnet: Subnet) -> bool[src]
Tests if self includes subnet.
fn find_subnet<T: Into<CompactIpv4>>(&self, ip: T) -> Option<Subnet>[src]
Returns the subnet in self that contains ip.
Returns None if no subnet in self contains ip.
fn super_subnet(&self, subnet: Subnet) -> Option<Subnet>[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]
fn clone(&self) -> IpRange[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl Debug for IpRange[src]
impl PartialEq for IpRange[src]
fn eq(&self, __arg_0: &IpRange) -> bool[src]
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, __arg_0: &IpRange) -> bool[src]
This method tests for !=.
impl Eq for IpRange[src]
impl<'a> IntoIterator for &'a IpRange[src]
type Item = &'a Subnet
The type of the elements being iterated over.
type IntoIter = IpRangeIter<'a>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter[src]
Creates an iterator from a value. Read more
impl FromIterator<Subnet> for IpRange[src]
fn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = Subnet>, [src]
T: IntoIterator<Item = Subnet>,
Creates a value from an iterator. Read more
impl<'a> FromIterator<&'a Subnet> for IpRange[src]
fn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = &'a Subnet>, [src]
T: IntoIterator<Item = &'a Subnet>,
Creates a value from an iterator. Read more