Skip to content

Commit e2f26ef

Browse files
committed
Merge pull request #77 from pcwalton/serde
Allow colors to be serialized with `serde`.
2 parents 26a3c05 + 8c03210 commit e2f26ef

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@ license = "MPL-2.0"
1616
rustc-serialize = "0.3"
1717
tempdir = "0.3"
1818

19+
[dependencies.serde]
20+
optional = true
21+
22+
[dependencies.serde_macros]
23+
optional = true
1924

2025
[dependencies]
2126
encoding = "0.2"
2227
matches = "0.1"
28+
29+
[features]
30+
serde-serialization = [ "serde", "serde_macros" ]
31+

src/color.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use super::{Token, Parser, ToCss};
1010

1111
/// A color with red, green, blue, and alpha components.
1212
#[derive(Clone, Copy, PartialEq, Debug)]
13+
#[cfg_attr(feature = "serde-serialization", derive(Deserialize, Serialize))]
1314
pub struct RGBA {
1415
/// The red channel. Nominally in 0.0 ... 1.0.
1516
pub red: f32,

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#![crate_type = "rlib"]
77

88
#![deny(missing_docs)]
9+
#![cfg_attr(feature = "serde-serialization", feature(custom_derive))]
10+
#![cfg_attr(feature = "serde-serialization", feature(plugin))]
11+
#![cfg_attr(feature = "serde-serialization", plugin(serde_macros))]
912

1013
/*!
1114
@@ -67,6 +70,7 @@ extern crate encoding;
6770
#[macro_use] extern crate matches;
6871
#[cfg(test)] extern crate tempdir;
6972
#[cfg(test)] extern crate rustc_serialize;
73+
#[cfg(feature = "serde-serialization")] extern crate serde;
7074

7175
pub use tokenizer::{Token, NumericValue, PercentageValue, SourceLocation};
7276
pub use rules_and_declarations::{parse_important};

0 commit comments

Comments
 (0)