Skip to content

Commit

Permalink
Merge #24
Browse files Browse the repository at this point in the history
24: Update serde to 1.0 and remove rustc-serialize r=cuviper a=Emerentius

Fixes #9

Co-authored-by: Emerentius <emerentius@arcor.de>
  • Loading branch information
bors[bot] and Emerentius committed Apr 12, 2018
2 parents 840c54f + 282887b commit 06f0e26
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@ default-features = false
version = "0.2.1"
default-features = false

[dependencies.rustc-serialize]
optional = true
version = "0.3.19"

[dependencies.serde]
optional = true
version = ">= 0.7.0, < 0.9.0"
version = "1.0.0"
default-features = false

[features]
default = ["bigint", "rustc-serialize", "std"]
default = ["bigint", "std"]
bigint = ["num-bigint", "std"]
std = ["num-traits/std"]
6 changes: 1 addition & 5 deletions ci/test_full.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ cargo build --no-default-features
cargo test --no-default-features

# Each isolated feature should also work everywhere.
for feature in bigint rustc-serialize serde std; do
for feature in bigint serde std; do
cargo build --verbose --no-default-features --features="$feature"
cargo test --verbose --no-default-features --features="$feature"
done

# Downgrade serde and build test the 0.7.0 channel as well
cargo update -p serde --precise 0.7.0
cargo build --verbose --no-default-features --features "serde"
17 changes: 8 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "rustc-serialize")]
extern crate rustc_serialize;
#[cfg(feature = "serde")]
extern crate serde;
#[cfg(feature = "num-bigint")]
Expand Down Expand Up @@ -50,7 +48,6 @@ use traits::Float;

/// Represents the ratio between two numbers.
#[derive(Copy, Clone, Debug)]
#[cfg_attr(all(feature = "std", feature = "rustc-serialize"), derive(RustcEncodable, RustcDecodable))]
#[allow(missing_docs)]
pub struct Ratio<T> {
/// Numerator.
Expand Down Expand Up @@ -887,23 +884,25 @@ impl<T> Into<(T, T)> for Ratio<T> {
impl<T> serde::Serialize for Ratio<T>
where T: serde::Serialize + Clone + Integer + PartialOrd
{
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: serde::Serializer
{
(self.numer(), self.denom()).serialize(serializer)
}
}

#[cfg(feature = "serde")]
impl<T> serde::Deserialize for Ratio<T>
where T: serde::Deserialize + Clone + Integer + PartialOrd
impl<'de, T> serde::Deserialize<'de> for Ratio<T>
where T: serde::Deserialize<'de> + Clone + Integer + PartialOrd
{
fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error>
where D: serde::Deserializer
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: serde::Deserializer<'de>
{
use serde::de::Unexpected;
use serde::de::Error;
let (numer, denom): (T,T) = try!(serde::Deserialize::deserialize(deserializer));
if denom.is_zero() {
Err(serde::de::Error::invalid_value("denominator is zero"))
Err(Error::invalid_value(Unexpected::Signed(0), &"a ratio with non-zero denominator"))
} else {
Ok(Ratio::new_raw(numer, denom))
}
Expand Down

0 comments on commit 06f0e26

Please sign in to comment.