diff --git a/.travis.yml b/.travis.yml index 9937f171..90605ea0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,14 +3,22 @@ language: rust notifications: webhooks: http://build.servo.org:54856/travis +rust: + - 1.23.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 diff --git a/Cargo.toml b/Cargo.toml index 485444d1..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/" @@ -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,