Skip to content

Allow serde 0.8 and remove use of compiler plugins #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] &&
Expand Down
10 changes: 4 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "cssparser"
version = "0.5.6"
version = "0.5.7"
authors = [ "Simon Sapin <[email protected]>" ]

description = "Rust implementation of CSS Syntax Level 3"
Expand All @@ -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" ]
37 changes: 33 additions & 4 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -23,6 +22,34 @@ pub struct RGBA {
pub alpha: f32,
}

#[cfg(feature = "serde")]
impl Serialize for RGBA {
fn serialize<S>(&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<D>(deserializer: &mut D) -> Result<Self, D::Error>
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<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
if self.alpha == 1f32 {
Expand All @@ -42,14 +69,16 @@ impl ToCss for RGBA {

/// A <color> value.
#[derive(Clone, Copy, PartialEq, Debug)]
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub enum Color {
/// The 'currentColor' keyword
CurrentColor,
/// Everything else gets converted to RGBA during parsing
RGBA(RGBA),
}

#[cfg(feature = "heapsize")]
known_heap_size!(0, Color);

impl ToCss for Color {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match self {
Expand Down
10 changes: 2 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]

/*!

Expand Down Expand Up @@ -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};
Expand Down
5 changes: 3 additions & 2 deletions src/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -363,7 +365,6 @@ impl TokenSerializationType {
}

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
enum TokenSerializationTypeVariants {
Nothing,
WhiteSpace,
Expand Down