From 48ecb8e7931455c28d47ef64a769d985e2350cd3 Mon Sep 17 00:00:00 2001 From: Keenan Tims Date: Tue, 12 Dec 2023 04:18:31 -0800 Subject: [PATCH] cleanup: make rayon optional --- Cargo.toml | 7 +++++-- src/iputils.rs | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b5d1095..3c94fa6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rs-aggregate" -version = "0.3.1" +version = "0.3.2" authors = ["Keenan Tims "] 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" diff --git a/src/iputils.rs b/src/iputils.rs index 47ea0ed..9821ada 100644 --- a/src/iputils.rs +++ b/src/iputils.rs @@ -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 { self.v4.iter()