Crates.io | prefixset |
lib.rs | prefixset |
version | 0.1.0-rc.2 |
source | src |
created_at | 2021-08-04 10:38:43.832578 |
updated_at | 2021-08-22 07:16:49.32393 |
description | An efficient set container for IP address prefixes |
homepage | |
repository | https://github.com/wolcomm/prefix-set-rs |
max_upload_size | |
id | 431463 |
size | 71,191,744 |
A Rust library crate prefixset
, providing a set-like container for IP
prefixes (not IP addresses).
Sets of prefixes are stored in a binary radix tree structure that provides:
This is a Rust implementation derived in large part from the internal
data-structure used in the widely used bgpq3
tool by Alexandre Snarskii,
packaged as a library, and with the set-theoretic operations added.
Full documentation can be found here.
extern crate prefixset;
use prefixset::{Error, Ipv6Prefix, IpPrefixRange, PrefixSet};
fn main() -> Result<(), Error> {
// create a set by parsing a Vec<&str>
let set = vec![
"2001:db8::/37",
"2001:db8:f00::/37",
]
.iter()
.map(|s| s.parse::<Ipv6Prefix>())
.collect::<Result<PrefixSet<_>, _>>()?;
// create a range by parsing a &str and providing the lower
// and upper prefix lenth bounds
let range = IpPrefixRange::new("2001:db8::/36".parse()?, 37, 37)?;
assert_eq!(set.ranges().collect::<Vec<_>>(), vec![range]);
Ok(())
}