From 9a8f7977fa5457e00534d0e1fb555da34ea4aee5 Mon Sep 17 00:00:00 2001 From: PizzaIter Date: Sun, 28 Jan 2018 15:31:41 +0100 Subject: [PATCH 1/4] Make serde optional --- Cargo.toml | 2 +- src/length.rs | 30 +++++++++++++++++++----------- src/lib.rs | 1 + src/macros.rs | 2 ++ src/rect.rs | 3 +++ src/rotation.rs | 3 ++- src/scale.rs | 3 +++ 7 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 485444d1..e969e845 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ unstable = [] [dependencies] num-traits = {version = "0.1.32", default-features = false} -serde = { version = "1.0", features = ["serde_derive"] } +serde = { version = "1.0", features = ["serde_derive"], optional = true } [dev-dependencies] rand = "0.3.7" diff --git a/src/length.rs b/src/length.rs index 1d59097f..08604e57 100644 --- a/src/length.rs +++ b/src/length.rs @@ -13,6 +13,7 @@ use num::Zero; use num_traits::{NumCast, Saturating}; use num::One; +#[cfg(feature = "serde")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::cmp::Ordering; use std::ops::{Add, Div, Mul, Neg, Sub}; @@ -42,6 +43,7 @@ impl Clone for Length { impl Copy for Length {} +#[cfg(feature = "serde")] impl<'de, Unit, T> Deserialize<'de> for Length where T: Deserialize<'de>, @@ -57,6 +59,7 @@ where } } +#[cfg(feature = "serde")] impl Serialize for Length where T: Serialize, @@ -260,15 +263,27 @@ mod tests { use scale::TypedScale; use std::f32::INFINITY; - extern crate serde_test; - use self::serde_test::Token; - use self::serde_test::assert_tokens; - enum Inch {} enum Mm {} enum Cm {} enum Second {} + #[cfg(feature = "serde")] + mod serde { + use super::*; + + extern crate serde_test; + use self::serde_test::Token; + use self::serde_test::assert_tokens; + + #[test] + fn test_length_serde() { + let one_cm: Length = Length::new(10.0); + + assert_tokens(&one_cm, &[Token::F32(10.0)]); + } + } + #[test] fn test_clone() { // A cloned Length is a separate length with the state matching the @@ -282,13 +297,6 @@ mod tests { assert_eq!(variable_length.get(), 24.0); } - #[test] - fn test_length_serde() { - let one_cm: Length = Length::new(10.0); - - assert_tokens(&one_cm, &[Token::F32(10.0)]); - } - #[test] fn test_get_clones_length_value() { // Calling get returns a clone of the Length's value. diff --git a/src/lib.rs b/src/lib.rs index 10cc5a19..2c23cf95 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,6 +55,7 @@ //! assert_eq!(p.x, p.x_typed().get()); //! ``` +#[cfg(feature = "serde")] #[macro_use] extern crate serde; diff --git a/src/macros.rs b/src/macros.rs index c88f010b..b0a455bc 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -32,6 +32,7 @@ macro_rules! define_matrix { impl Copy for $name {} + #[cfg(feature = "serde")] impl<'de, T, $($phantom),+> ::serde::Deserialize<'de> for $name where T: ::serde::Deserialize<'de> { @@ -47,6 +48,7 @@ macro_rules! define_matrix { } } + #[cfg(feature = "serde")] impl ::serde::Serialize for $name where T: ::serde::Serialize { diff --git a/src/rect.rs b/src/rect.rs index b17a2a32..620c4468 100644 --- a/src/rect.rs +++ b/src/rect.rs @@ -17,6 +17,7 @@ use side_offsets::TypedSideOffsets2D; use size::TypedSize2D; use num_traits::NumCast; +#[cfg(feature = "serde")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::cmp::PartialOrd; use std::fmt; @@ -33,6 +34,7 @@ pub struct TypedRect { /// The default rectangle type with no unit. pub type Rect = TypedRect; +#[cfg(feature = "serde")] impl<'de, T: Copy + Deserialize<'de>, U> Deserialize<'de> for TypedRect { fn deserialize(deserializer: D) -> Result where @@ -43,6 +45,7 @@ impl<'de, T: Copy + Deserialize<'de>, U> Deserialize<'de> for TypedRect { } } +#[cfg(feature = "serde")] impl Serialize for TypedRect { fn serialize(&self, serializer: S) -> Result where diff --git a/src/rotation.rs b/src/rotation.rs index 47ef41a7..70e62783 100644 --- a/src/rotation.rs +++ b/src/rotation.rs @@ -17,7 +17,8 @@ use {TypedPoint2D, TypedPoint3D, TypedVector2D, TypedVector3D, Vector3D, point2, use {TypedTransform2D, TypedTransform3D, UnknownUnit}; /// An angle in radians -#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Hash, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Angle { pub radians: T, } diff --git a/src/scale.rs b/src/scale.rs index cc1ea34f..8aff0e51 100644 --- a/src/scale.rs +++ b/src/scale.rs @@ -11,6 +11,7 @@ use num::One; use num_traits::NumCast; +#[cfg(feature = "serde")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::fmt; use std::ops::{Add, Div, Mul, Neg, Sub}; @@ -39,6 +40,7 @@ use {TypedPoint2D, TypedRect, TypedSize2D, TypedVector2D}; #[repr(C)] pub struct TypedScale(pub T, PhantomData<(Src, Dst)>); +#[cfg(feature = "serde")] impl<'de, T, Src, Dst> Deserialize<'de> for TypedScale where T: Deserialize<'de>, @@ -54,6 +56,7 @@ where } } +#[cfg(feature = "serde")] impl Serialize for TypedScale where T: Serialize, From 4bc9b075c65fb18afa77eb035560b80c369688c2 Mon Sep 17 00:00:00 2001 From: PizzaIter Date: Mon, 29 Jan 2018 21:58:11 +0100 Subject: [PATCH 2/4] Add Travis-CI jobs for serde feature --- .travis.yml | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9937f171..9c5a556a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,14 +3,22 @@ language: rust notifications: webhooks: http://build.servo.org:54856/travis +rust: + - 1.21.0 + - stable + - beta + - nightly + +env: + - FEATURES="" + - FEATURES="--features serde" + matrix: include: - - rust: 1.21.0 - - rust: stable - - rust: beta - - rust: nightly - rust: nightly env: FEATURES="--features unstable" + - rust: nightly + env: FEATURES="--features unstable,serde" script: - cargo build $FEATURES From add35f194a2da65a2b57d4a5c87398ce4506b0f7 Mon Sep 17 00:00:00 2001 From: PizzaIter Date: Tue, 30 Jan 2018 20:46:04 +0100 Subject: [PATCH 3/4] Bump rust version for Travis-CI jobs --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9c5a556a..90605ea0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ notifications: webhooks: http://build.servo.org:54856/travis rust: - - 1.21.0 + - 1.23.0 - stable - beta - nightly From 977e136050f73b079db4cf4ff81f36fd14b65b47 Mon Sep 17 00:00:00 2001 From: PizzaIter Date: Tue, 30 Jan 2018 20:48:31 +0100 Subject: [PATCH 4/4] Version 0.17.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index e969e845..ec88ce7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "euclid" -version = "0.16.4" +version = "0.17.0" authors = ["The Servo Project Developers"] description = "Geometry primitives" documentation = "https://docs.rs/euclid/"