Skip to content

Commit

Permalink
serde feature implied by optional dep
Browse files Browse the repository at this point in the history
  • Loading branch information
smklein committed Feb 16, 2022
1 parent ae98506 commit e34c914
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
7 changes: 1 addition & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,11 @@ documentation = "https://docs.rs/ipnet"

[features]
default = []
# Implements "serde::Serialize" and "serde::Deserialize".
serde = ["serde_crate"]
# Implements "schemars::JsonSchema". Also implies "serde".
json = ["serde", "schemars"]

[dependencies]
# "serde" is renamed to "serde_crate" to avoid a feature vs dependency
# name conflict. For more context:
# https://github.com/rust-lang/api-guidelines/discussions/180
serde_crate = { package = "serde", version = "1", features = ["derive"], optional = true }
serde = { package = "serde", version = "1", features = ["derive"], optional = true }
schemars = { version = "0.8", optional = true }

[dev-dependencies]
Expand Down
9 changes: 4 additions & 5 deletions src/ipnet_serde.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use {IpNet, Ipv4Net, Ipv6Net};
use std::fmt;
use std::net::{Ipv4Addr, Ipv6Addr};
use serde_crate::{self, Serialize, Deserialize, Serializer, Deserializer};
use serde_crate::ser::SerializeTuple;
use serde_crate::de::{EnumAccess, Error, VariantAccess, Visitor};
use serde::{self, Serialize, Deserialize, Serializer, Deserializer};
use serde::ser::SerializeTuple;
use serde::de::{EnumAccess, Error, VariantAccess, Visitor};

impl Serialize for IpNet {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
Expand Down Expand Up @@ -49,7 +49,6 @@ impl<'de> Deserialize<'de> for IpNet {
struct EnumVisitor;

#[derive(Serialize, Deserialize)]
#[serde(crate = "serde_crate")]
enum IpNetKind {
V4,
V6,
Expand Down Expand Up @@ -118,7 +117,7 @@ impl<'de> Deserialize<'de> for Ipv4Net {
deserializer.deserialize_str(IpAddrVisitor)
} else {
let b = <[u8; 5]>::deserialize(deserializer)?;
Ipv4Net::new(Ipv4Addr::new(b[0], b[1], b[2], b[3]), b[4]).map_err(serde_crate::de::Error::custom)
Ipv4Net::new(Ipv4Addr::new(b[0], b[1], b[2], b[3]), b[4]).map_err(serde::de::Error::custom)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
//! [feature]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section
#[cfg(feature = "serde")]
extern crate serde_crate;
extern crate serde;

pub use self::ipext::{IpAdd, IpSub, IpBitAnd, IpBitOr, IpAddrRange, Ipv4AddrRange, Ipv6AddrRange};
pub use self::ipnet::{IpNet, Ipv4Net, Ipv6Net, PrefixLenError, IpSubnets, Ipv4Subnets, Ipv6Subnets};
Expand Down

0 comments on commit e34c914

Please sign in to comment.