cleanup: make rayon optional

This commit is contained in:
Keenan Tims 2023-12-12 04:18:31 -08:00
parent d5002b9538
commit 48ecb8e793
Signed by: ktims
GPG Key ID: 11230674D69038D4
2 changed files with 12 additions and 2 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "rs-aggregate"
version = "0.3.1"
version = "0.3.2"
authors = ["Keenan Tims <ktims@gotroot.ca>"]
edition = "2021"
description = "Aggregate a list of IP prefixes into their minimum equivalent representation"
@ -10,11 +10,14 @@ license = "MIT"
categories = ["network-programming"]
exclude = [".github/*", "doc/*", "test-data/*"]
[features]
default = ["rayon"]
[dependencies]
clap = { version = "4.4.6", features = ["derive"] }
clio = { version = "0.3.4", features = ["clap-parse"] }
ipnet = "2.8.0"
rayon = "1.8.0"
rayon = { version = "1.8.0", optional = true }
[dev-dependencies]
assert_cmd = "2.0.10"

View File

@ -1,3 +1,4 @@
#[cfg(feature = "rayon")]
use rayon::join;
use std::{
error::Error,
@ -24,12 +25,18 @@ impl IpBothRange {
IpNet::V6(n) => self.v6.push(n),
}
}
#[cfg(feature = "rayon")]
pub fn simplify(&mut self) {
(self.v4, self.v6) = join(
|| Ipv4Net::aggregate(&self.v4),
|| Ipv6Net::aggregate(&self.v6),
);
}
#[cfg(not(feature = "rayon"))]
pub fn simplify(&mut self) {
self.v4 = Ipv4Net::aggregate(&self.v4);
self.v6 = Ipv6Net::aggregate(&self.v6);
}
pub fn v4_iter(&self) -> impl Iterator<Item = &Ipv4Net> {
self.v4.iter()