33 releases
0.4.1 | Dec 15, 2023 |
---|---|
0.4.0 | Dec 15, 2023 |
0.3.10 | Oct 31, 2023 |
0.3.7 | Aug 25, 2023 |
0.1.9 | Jun 9, 2023 |
#1054 in Network programming
224 downloads per month
Used in pistol
34KB
757 lines
subnetwork
Returns an iterator that iterates over all subnet IPs.
Example
use subnetwork::{Ipv4Pool,Ipv4};
fn main() {
let ipv4 = Ipv4::from("192.168.1.1").unwrap();
let ipv4_pool = Ipv4Pool::from("192.168.1.0/24").unwrap();
for i in ipv4.iter(24) {
println!("{:?}", i);
}
for i in ipv4_pool {
println!("{:?}", i);
}
let ret = ipv4_pool.contain_from_str("192.168.1.200").unwrap();
assert_eq!(ret, true);
let ret = ipv4_pool.contain(ipv4);
assert_eq!(ret, true);
let ret = ipv4.within_from_str("192.168.1.0/24").unwarp();
assert_eq!(ret, true);
let ret = ipv4.within(ipv4_pool);
assert_eq!(ret, true);
}
Benchmark
You can see how our performance compares to other similar libraries here.
lib.rs
:
The subnetwork
crate provides a set of APIs to work with IP CIDRs in Rust.