mirror of
https://github.com/achanda/ipnetwork.git
synced 2025-06-17 01:08:53 +00:00
Add Serde Feature for IpNetwork
This commit is contained in:
@ -11,7 +11,7 @@ env:
|
|||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- rust: nightly
|
- rust: nightly
|
||||||
env: FEATURES=ipv6-iterator,ipv6-methods
|
env: FEATURES=ipv6-iterator,ipv6-methods,with-serde
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- cargo build --features $FEATURES --verbose
|
- cargo build --features $FEATURES --verbose
|
||||||
|
@ -12,6 +12,8 @@ categories = ["network-programming", "os"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clippy = {version = "0.0.104", optional = true}
|
clippy = {version = "0.0.104", optional = true}
|
||||||
|
serde = { version = ">=0.8.0, <2.0", optional = true }
|
||||||
|
serde_derive = { version = ">=0.8.0, <2.0", optional = true }
|
||||||
|
|
||||||
[badges]
|
[badges]
|
||||||
travis-ci = { repository = "achanda/ipnetwork" }
|
travis-ci = { repository = "achanda/ipnetwork" }
|
||||||
@ -21,3 +23,4 @@ default = []
|
|||||||
dev = ["clippy"]
|
dev = ["clippy"]
|
||||||
ipv6-iterator = []
|
ipv6-iterator = []
|
||||||
ipv6-methods = []
|
ipv6-methods = []
|
||||||
|
with-serde = ["serde", "serde_derive"]
|
||||||
|
@ -7,6 +7,7 @@ use common::{cidr_parts, parse_addr, parse_prefix, IpNetworkError};
|
|||||||
const IPV4_BITS: u8 = 32;
|
const IPV4_BITS: u8 = 32;
|
||||||
|
|
||||||
/// Represents a network range where the IP addresses are of v4
|
/// 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)]
|
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub struct Ipv4Network {
|
pub struct Ipv4Network {
|
||||||
addr: Ipv4Addr,
|
addr: Ipv4Addr,
|
||||||
|
@ -9,6 +9,7 @@ const IPV6_BITS: u8 = 128;
|
|||||||
const IPV6_SEGMENT_BITS: u8 = 16;
|
const IPV6_SEGMENT_BITS: u8 = 16;
|
||||||
|
|
||||||
/// Represents a network range where the IP addresses are of v6
|
/// 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)]
|
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub struct Ipv6Network {
|
pub struct Ipv6Network {
|
||||||
addr: Ipv6Addr,
|
addr: Ipv6Addr,
|
||||||
|
@ -8,6 +8,12 @@
|
|||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
#![doc(html_root_url = "https://docs.rs/ipnetwork/0.12.7")]
|
#![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::fmt;
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
|
|
||||||
@ -23,6 +29,7 @@ pub use common::IpNetworkError;
|
|||||||
|
|
||||||
/// Represents a generic network range. This type can have two variants:
|
/// Represents a generic network range. This type can have two variants:
|
||||||
/// the v4 and the v6 case.
|
/// the v4 and the v6 case.
|
||||||
|
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
|
||||||
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
pub enum IpNetwork {
|
pub enum IpNetwork {
|
||||||
V4(Ipv4Network),
|
V4(Ipv4Network),
|
||||||
|
Reference in New Issue
Block a user