Skip to content

Commit

Permalink
Add unit structs for representing keywords: auto, none, normal
Browse files Browse the repository at this point in the history
  • Loading branch information
wafflespeanut committed Nov 9, 2016
1 parent f36a573 commit 5df250b
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions components/style/values/mod.rs
Expand Up @@ -63,6 +63,41 @@ impl<T> HasViewportPercentage for T where T: NoViewportPercentage {
}
}

use self::computed::ComputedValueAsSpecified;

macro_rules! define_keyword_type {
($name: ident, $css: expr) => {
#[derive(Clone, PartialEq, Copy)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct $name;

impl ::style_traits::ToCss for $name {
fn to_css<W>(&self, dest: &mut W) -> ::std::fmt::Result where W: ::std::fmt::Write {
write!(dest, $css)
}
}

impl fmt::Debug for $name {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, $css)
}
}

impl Parse for $name {
fn parse(input: &mut ::cssparser::Parser) -> Result<$name, ()> {
input.expect_ident_matching($css).map(|_| $name)
}
}

impl ComputedValueAsSpecified for $name {}
impl NoViewportPercentage for $name {}
};
}

define_keyword_type!(None_, "none");
define_keyword_type!(Auto, "auto");
define_keyword_type!(Normal, "normal");

#[derive(Clone, PartialEq, Copy)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum Either<A, B> {
Expand Down

0 comments on commit 5df250b

Please sign in to comment.