make `serde` optional

This commit is contained in:
Andrew Poelstra 2017-12-19 22:40:06 +00:00
parent 12e9f4b90b
commit 5c54698bf9
4 changed files with 15 additions and 5 deletions

View File

@ -25,13 +25,13 @@ unstable = []
default = []
[dev-dependencies]
serde = "1.0"
serde_json = "1.0"
rand = "0.3"
rustc-serialize = "0.3"
[dependencies]
libc = "0.2"
serde = "1.0"
[dependencies.rand]
version = "0.3"
@ -41,3 +41,8 @@ optional = true
version = "0.3"
optional = true
[dependencies.serde]
version = "1.0"
optional = true

View File

@ -15,10 +15,10 @@
//! # Public and secret keys
use std::marker;
#[cfg(any(test, feature = "serde"))] use std::marker;
#[cfg(any(test, feature = "rand"))] use rand::Rng;
#[cfg(any(test, feature = "rustc-serialize"))] use serialize::{Decoder, Decodable, Encoder, Encodable};
use serde::{Serialize, Deserialize, Serializer, Deserializer};
#[cfg(any(test, feature = "serde"))] use serde::{Serialize, Deserialize, Serializer, Deserializer};
use super::{Secp256k1, ContextFlag};
use super::Error::{self, IncapableContext, InvalidPublicKey, InvalidSecretKey};
@ -300,6 +300,7 @@ impl Encodable for PublicKey {
}
}
#[cfg(any(test, feature = "serde"))]
impl<'de> Deserialize<'de> for PublicKey {
fn deserialize<D>(d: D) -> Result<PublicKey, D::Error>
where D: Deserializer<'de>
@ -360,6 +361,7 @@ impl<'de> Deserialize<'de> for PublicKey {
}
}
#[cfg(any(test, feature = "serde"))]
impl Serialize for PublicKey {
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
where S: Serializer

View File

@ -38,12 +38,11 @@
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
#[cfg(all(test, feature = "unstable"))] extern crate test;
#[cfg(any(test, feature = "serde"))] extern crate serde;
#[cfg(test)] extern crate serde_json as json;
#[cfg(any(test, feature = "rand"))] extern crate rand;
#[cfg(any(test, feature = "rustc-serialize"))] extern crate rustc_serialize as serialize;
extern crate serde;
extern crate libc;
use libc::size_t;
@ -201,6 +200,7 @@ impl Signature {
}
}
#[cfg(any(test, feature = "serde"))]
impl serde::Serialize for Signature {
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
where S: serde::Serializer
@ -210,6 +210,7 @@ impl serde::Serialize for Signature {
}
}
#[cfg(any(test, feature = "serde"))]
impl<'de> serde::Deserialize<'de> for Signature {
fn deserialize<D>(d: D) -> Result<Signature, D::Error>
where D: serde::Deserializer<'de>

View File

@ -146,6 +146,7 @@ macro_rules! impl_array_newtype {
}
}
#[cfg(any(test, feature = "serde"))]
impl<'de> ::serde::Deserialize<'de> for $thing {
fn deserialize<D>(d: D) -> Result<$thing, D::Error>
where D: ::serde::Deserializer<'de>
@ -190,6 +191,7 @@ macro_rules! impl_array_newtype {
}
}
#[cfg(any(test, feature = "serde"))]
impl ::serde::Serialize for $thing {
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
where S: ::serde::Serializer