Add Serde Feature for IpNetwork

This commit is contained in:
admwrd
2018-03-14 04:32:45 -07:00
parent 3703488473
commit c9e25e15fa
5 changed files with 13 additions and 1 deletions

View File

@ -7,6 +7,7 @@ use common::{cidr_parts, parse_addr, parse_prefix, IpNetworkError};
const IPV4_BITS: u8 = 32;
/// Represents a network range where the IP addresses are of v4
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct Ipv4Network {
addr: Ipv4Addr,

View File

@ -9,6 +9,7 @@ const IPV6_BITS: u8 = 128;
const IPV6_SEGMENT_BITS: u8 = 16;
/// Represents a network range where the IP addresses are of v6
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct Ipv6Network {
addr: Ipv6Addr,

View File

@ -8,6 +8,12 @@
#![crate_type = "lib"]
#![doc(html_root_url = "https://docs.rs/ipnetwork/0.12.7")]
#[cfg(feature = "with-serde")]
extern crate serde;
#[cfg(feature = "with-serde")]
#[macro_use]
extern crate serde_derive;
use std::fmt;
use std::net::IpAddr;
@ -23,6 +29,7 @@ pub use common::IpNetworkError;
/// Represents a generic network range. This type can have two variants:
/// the v4 and the v6 case.
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub enum IpNetwork {
V4(Ipv4Network),