diff --git a/.travis.yml b/.travis.yml index e95df823..bf271d65 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ script: - cargo build --verbose - cargo test --verbose - cargo doc --verbose - - ([ $TRAVIS_RUST_VERSION != nightly ] || cargo test --features heap_size) + - cargo test --features heapsize after_success: | [ $TRAVIS_RUST_VERSION = nightly ] && diff --git a/Cargo.toml b/Cargo.toml index 46cba33b..616d7d96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "cssparser" -version = "0.5.6" +version = "0.5.7" authors = [ "Simon Sapin " ] description = "Rust implementation of CSS Syntax Level 3" @@ -19,11 +19,9 @@ tempdir = "0.3" [dependencies] encoding = "0.2" heapsize = {version = ">=0.1.1, <0.4.0", optional = true} -heapsize_plugin = {version = "0.1.0", optional = true} matches = "0.1" -serde = {version = ">=0.6.6, <0.8", optional = true} -serde_macros = {version = ">=0.6.5, <0.8", optional = true} +serde = {version = ">=0.6.6, <0.9", optional = true} [features] -serde-serialization = [ "serde", "serde_macros" ] -heap_size = [ "heapsize", "heapsize_plugin" ] +serde-serialization = [ "serde" ] +heap_size = [ "heapsize" ] diff --git a/src/color.rs b/src/color.rs index d64ca77a..12f6fa85 100644 --- a/src/color.rs +++ b/src/color.rs @@ -2,16 +2,15 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use std::ascii::AsciiExt; use std::fmt; use super::{Token, Parser, ToCss}; +#[cfg(feature = "serde")] +use serde::{Deserialize, Deserializer, Serialize, Serializer}; /// A color with red, green, blue, and alpha components. #[derive(Clone, Copy, PartialEq, Debug)] -#[cfg_attr(feature = "serde-serialization", derive(Deserialize, Serialize))] -#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))] pub struct RGBA { /// The red channel. Nominally in 0.0 ... 1.0. pub red: f32, @@ -23,6 +22,34 @@ pub struct RGBA { pub alpha: f32, } +#[cfg(feature = "serde")] +impl Serialize for RGBA { + fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> + where S: Serializer + { + (self.red, self.green, self.blue, self.alpha).serialize(serializer) + } +} + +#[cfg(feature = "serde")] +impl Deserialize for RGBA { + fn deserialize(deserializer: &mut D) -> Result + where D: Deserializer + { + let (red, green, blue, alpha) = + try!(Deserialize::deserialize(deserializer)); + Ok(RGBA { + red: red, + green: green, + blue: blue, + alpha: alpha, + }) + } +} + +#[cfg(feature = "heapsize")] +known_heap_size!(0, RGBA); + impl ToCss for RGBA { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { if self.alpha == 1f32 { @@ -42,7 +69,6 @@ impl ToCss for RGBA { /// A value. #[derive(Clone, Copy, PartialEq, Debug)] -#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))] pub enum Color { /// The 'currentColor' keyword CurrentColor, @@ -50,6 +76,9 @@ pub enum Color { RGBA(RGBA), } +#[cfg(feature = "heapsize")] +known_heap_size!(0, Color); + impl ToCss for Color { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { match self { diff --git a/src/lib.rs b/src/lib.rs index 85803843..87cc75b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,12 +6,6 @@ #![crate_type = "rlib"] #![deny(missing_docs)] -#![cfg_attr(feature = "serde-serialization", feature(custom_derive))] -#![cfg_attr(feature = "serde-serialization", feature(plugin))] -#![cfg_attr(feature = "serde-serialization", plugin(serde_macros))] -#![cfg_attr(feature = "heap_size", feature(custom_derive))] -#![cfg_attr(feature = "heap_size", feature(plugin))] -#![cfg_attr(feature = "heap_size", plugin(heapsize_plugin))] /*! @@ -75,8 +69,8 @@ extern crate encoding; #[macro_use] extern crate matches; #[cfg(test)] extern crate tempdir; #[cfg(test)] extern crate rustc_serialize; -#[cfg(feature = "serde-serialization")] extern crate serde; -#[cfg(feature = "heap_size")] extern crate heapsize; +#[cfg(feature = "serde")] extern crate serde; +#[cfg(feature = "heapsize")] #[macro_use] extern crate heapsize; pub use tokenizer::{Token, NumericValue, PercentageValue, SourceLocation}; pub use rules_and_declarations::{parse_important}; diff --git a/src/serializer.rs b/src/serializer.rs index 69b7255b..ded6bb21 100644 --- a/src/serializer.rs +++ b/src/serializer.rs @@ -314,9 +314,11 @@ impl_tocss_for_number!(u64); /// A category of token. See the `needs_separator_when_before` method. #[derive(Copy, Clone, Eq, PartialEq, Debug)] -#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))] pub struct TokenSerializationType(TokenSerializationTypeVariants); +#[cfg(feature = "heapsize")] +known_heap_size!(0, TokenSerializationType); + impl TokenSerializationType { /// Return a value that represents the absence of a token, e.g. before the start of the input. pub fn nothing() -> TokenSerializationType { @@ -363,7 +365,6 @@ impl TokenSerializationType { } #[derive(Copy, Clone, Eq, PartialEq, Debug)] -#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))] enum TokenSerializationTypeVariants { Nothing, WhiteSpace,