Repository: achanda/ipnetwork (language: rust)

Issue:
JSONSchema implementation
Hi there!
I was trying to make a json schema for [wg-bond](https://github.com/cab404/wg-bond/issues) (via [schemars](https://docs.rs/schemars/latest/schemars/)), and got stuck on missing implementation for IpNetwork. Can I add implementation of JsonSchema for your stuff in your crate?


Discussion / hints:
HI, @cab404 please feel free to add a JsonSchema implementation. Thank you!

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index d498210..5f7e589 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,6 +12,7 @@ edition = "2021"
 
 [dependencies]
 serde = { version = "1", optional = true }
+schemars = { version = "0.8.10", optional = true }
 
 [dev-dependencies]
 serde_json = "1.0"
diff --git a/src/ipv4.rs b/src/ipv4.rs
index 9fde814..c681b2c 100644
--- a/src/ipv4.rs
+++ b/src/ipv4.rs
@@ -5,6 +5,7 @@ const IPV4_BITS: u8 = 32;
 
 /// Represents a network range where the IP addresses are of v4
 #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
+#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
 pub struct Ipv4Network {
     addr: Ipv4Addr,
     prefix: u8,
diff --git a/src/ipv6.rs b/src/ipv6.rs
index 3928ff5..dfce6c4 100644
--- a/src/ipv6.rs
+++ b/src/ipv6.rs
@@ -6,6 +6,7 @@ const IPV6_SEGMENT_BITS: u8 = 16;
 
 /// Represents a network range where the IP addresses are of v6
 #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
+#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
 pub struct Ipv6Network {
     addr: Ipv6Addr,
     prefix: u8,
diff --git a/src/lib.rs b/src/lib.rs
index 002b46a..546e902 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -23,6 +23,7 @@ pub use crate::ipv6::{ipv6_mask_to_prefix, Ipv6Network};
 /// Represents a generic network range. This type can have two variants:
 /// the v4 and the v6 case.
 #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
+#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
 pub enum IpNetwork {
     V4(Ipv4Network),
     V6(Ipv6Network),


Test patch: