pub struct IpRange<N: IpNet> { /* private fields */ }
Expand description
A set of networks that supports various operations:
IntoIter
is implemented for &IpRange
. So, you can use for
to iterate over the networks in an IpRange
:
extern crate ipnet;
extern crate iprange;
use iprange::IpRange;
use ipnet::Ipv4Net;
fn main() {
let ip_range: IpRange<Ipv4Net> = ["172.16.0.0/16", "192.168.1.0/24"]
.iter()
.map(|s| s.parse().unwrap())
.collect();
for network in &ip_range {
println!("{:?}", network);
}
}
Implementations
Add a network to self
.
Returns &mut self
in order to enable method chaining.
Pay attention that this operation will not combine two
networks automatically. To do this, call simplify
method
explicitly. For example:
extern crate iprange;
extern crate ipnet;
use iprange::IpRange;
use ipnet::Ipv4Net;
fn main() {
let mut ip_range: IpRange<Ipv4Net> = 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);
}
Remove a network from self
.
Returns &mut self
in order to enable method chaining.
self
does not necessarily has exactly the network to be removed.
The network can be a networkwork of a network in self
.
This method will do splitting and remove the corresponding network.
For example:
extern crate iprange;
extern crate ipnet;
use iprange::IpRange;
use ipnet::Ipv4Net;
fn main() {
let mut ip_range: IpRange<Ipv4Net> = 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 network: "192.168.1.0/24".
}
Returns true
if the self
has no network.
Examples
let mut ip_range = IpRange::new();
let network: Ipv4Net = "1.0.1.0/24".parse().unwrap();
ip_range.add(network.clone());
ip_range.remove(network);
assert!(ip_range.is_empty());
Simplify self
by combining networks. For example:
extern crate iprange;
extern crate ipnet;
use iprange::IpRange;
use ipnet::Ipv4Net;
fn main() {
let mut ip_range: IpRange<Ipv4Net> = 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 network: "192.168.0.0/19".
}
Returns a new IpRange
which contains all networks
that is either in self
or in other
.
The returned IpRange
is simplified.
Returns a new IpRange
which contains all networks
that is in both self
and other
.
The returned IpRange
is simplified.
Returns a new IpRange
which contains all networks
that is in self
while not in other
.
The returned IpRange
is simplified.
Tests if self
contains network
.
network
is anything that can be converted into N
.
See ToNetwork<N>
for detail.
Returns the network in self
which is the supernetwork of network
.
Returns None if no network in self
contains network
.
pub fn iter(&self) -> IpRangeIter<'_, N>ⓘNotable traits for IpRangeIter<'a, N>impl<'a, N> Iterator for IpRangeIter<'a, N> where
N: IpNet, type Item = N;
pub fn iter(&self) -> IpRangeIter<'_, N>ⓘNotable traits for IpRangeIter<'a, N>impl<'a, N> Iterator for IpRangeIter<'a, N> where
N: IpNet, type Item = N;
impl<'a, N> Iterator for IpRangeIter<'a, N> where
N: IpNet, type Item = N;
Returns the iterator to &self
.
Trait Implementations
Auto Trait Implementations
impl<N> RefUnwindSafe for IpRange<N> where
N: RefUnwindSafe,
impl<N> UnwindSafe for IpRange<N> where
N: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more