From f51d2bbb8b206a621a9d57fd6766e050875abfcc Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Skutnik Date: Thu, 27 Nov 2025 12:02:12 +0100 Subject: [PATCH] Derive arbitrary on feature enablement --- Cargo.toml | 2 ++ src/ipnet.rs | 3 +++ 2 files changed, 5 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index caa401b..0704e52 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,11 +17,13 @@ std = [] # Implements "schemars::JsonSchema". Also implies "serde". json = ["serde", "schemars"] ser_as_str = ["heapless"] +arbitrary = ["dep:arbitrary"] [dependencies] serde = { package = "serde", version = "1", features = ["derive"], optional = true, default-features=false } schemars = { version = "0.8", optional = true } heapless = { version = "0", optional = true } +arbitrary = { version = "1", features = ["derive"], optional = true } [dev-dependencies] serde_test = "1" diff --git a/src/ipnet.rs b/src/ipnet.rs index cecb138..e7fc1db 100644 --- a/src/ipnet.rs +++ b/src/ipnet.rs @@ -48,6 +48,7 @@ use crate::mask::{ip_mask_to_prefix, ipv4_mask_to_prefix, ipv6_mask_to_prefix}; /// assert_eq!(Ok(net.network()), "fd00::".parse()); /// ``` #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] pub enum IpNet { V4(Ipv4Net), V6(Ipv6Net), @@ -81,6 +82,7 @@ pub enum IpNet { /// assert_eq!(Ok(net.network()), "10.1.1.0".parse()); /// ``` #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] pub struct Ipv4Net { addr: Ipv4Addr, prefix_len: u8, @@ -111,6 +113,7 @@ pub struct Ipv4Net { /// assert_eq!(Ok(net.network()), "fd00::".parse()); /// ``` #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] pub struct Ipv6Net { addr: Ipv6Addr, prefix_len: u8,