Skip to content

Commit

Permalink
Merge pull request #155 from sancho20021/153-JsonSchema-for-IPNetwork
Browse files Browse the repository at this point in the history
[#153] Add optional JSONSchema implementation for IpNetwork
  • Loading branch information
achanda authored May 31, 2022
2 parents 372f9bd + 86dbbd9 commit 5146125
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/ipv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/ipv6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 5146125

Please sign in to comment.