Derive the most trivial ToCss implementations 🌋

For now, all variants get serialised as the space-separated serialisations
of their fields. Unit variants are not supported.
This commit is contained in:
Anthony Ramine 2017-06-04 15:45:09 +02:00
parent 6d6f03974d
commit c4f1d647a0
18 changed files with 113 additions and 263 deletions

View file

@ -34,9 +34,9 @@ define_keyword_type!(None_, "none");
define_keyword_type!(Auto, "auto");
define_keyword_type!(Normal, "normal");
#[derive(Clone, Copy, HasViewportPercentage, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
/// A struct representing one of two kinds of values.
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Copy, HasViewportPercentage, PartialEq, ToCss)]
pub enum Either<A, B> {
/// The first value.
First(A),
@ -53,15 +53,6 @@ impl<A: Debug, B: Debug> Debug for Either<A, B> {
}
}
impl<A: ToCss, B: ToCss> ToCss for Either<A, B> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
Either::First(ref v) => v.to_css(dest),
Either::Second(ref v) => v.to_css(dest),
}
}
}
impl<A: Parse, B: Parse> Parse for Either<A, B> {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Either<A, B>, ()> {
if let Ok(v) = input.try(|i| A::parse(context, i)) {