Skip to content

Commit

Permalink
cleanup: make rayon optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ktims committed Dec 12, 2023
1 parent d5002b9 commit 48ecb8e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions src/iputils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "rayon")]
use rayon::join;
use std::{
error::Error,
Expand All @@ -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()
Expand Down

0 comments on commit 48ecb8e

Please sign in to comment.