Skip to content

Commit

Permalink
Prevent serde from bringing in std unless the std feature is enab…
Browse files Browse the repository at this point in the history
…led for this crate (#499)

* Prevent serde from bringing in `std` unless the `std` feature is enabled
for this crate.

* simplify serde usage

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <git@kchr.de>

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
  • Loading branch information
eranrund and bkchr committed Aug 17, 2023
1 parent 8d141aa commit 4cbd87b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ rust-version = "1.60.0"

[dependencies]
arrayvec = { version = "0.7", default-features = false }
serde = { version = "1.0.183", optional = true }
serde = { version = "1.0.183", default-features = false, optional = true }
parity-scale-codec-derive = { path = "derive", version = ">= 3.6.4", default-features = false, optional = true }
bitvec = { version = "1", default-features = false, features = [ "alloc" ], optional = true }
bytes = { version = "1", default-features = false, optional = true }
Expand Down Expand Up @@ -39,7 +39,7 @@ bench = false
[features]
default = ["std"]
derive = ["parity-scale-codec-derive"]
std = ["serde", "bitvec?/std", "byte-slice-cast/std", "chain-error"]
std = ["serde/std", "bitvec?/std", "byte-slice-cast/std", "chain-error"]
bit-vec = ["bitvec"]
fuzz = ["std", "arbitrary"]

Expand Down
4 changes: 2 additions & 2 deletions src/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ impl<T> core::fmt::Debug for Compact<T> where T: core::fmt::Debug {
}
}

#[cfg(feature = "std")]
#[cfg(feature = "serde")]
impl<T> serde::Serialize for Compact<T> where T: serde::Serialize {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
T::serialize(&self.0, serializer)
}
}

#[cfg(feature = "std")]
#[cfg(feature = "serde")]
impl<'de, T> serde::Deserialize<'de> for Compact<T> where T: serde::Deserialize<'de> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
T::deserialize(deserializer).map(Compact)
Expand Down

0 comments on commit 4cbd87b

Please sign in to comment.