Add unit structs for representing keywords: auto, none, normal

This commit is contained in:
Ravi Shankar 2016-11-03 21:10:03 +05:30
parent f36a573d2d
commit 5df250bc05

View file

@ -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)] #[derive(Clone, PartialEq, Copy)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum Either<A, B> { pub enum Either<A, B> {