style: Improve #[derive(Parse)].

I want to do this so that I can get rid of Either<>. The reasons for getting rid
of either are multiple:

 * It doesn't generate as nice C++ code using cbindgen.
 * It isn't that nice to use either from Rust.
 * cbindgen has bugs with zero-sized types.

I started using this for ColorOrAuto and a few others, for now.

Differential Revision: https://phabricator.services.mozilla.com/D19844
This commit is contained in:
Emilio Cobos Álvarez 2019-02-14 20:45:10 +01:00
parent 6118e4d993
commit 73d5b82f9f
24 changed files with 238 additions and 362 deletions

View file

@ -4,10 +4,6 @@
//! Generic types for url properties.
use crate::parser::{Parse, ParserContext};
use cssparser::Parser;
use style_traits::ParseError;
/// An image url or none, used for example in list-style-image
#[derive(
Animate,
@ -16,6 +12,7 @@ use style_traits::ParseError;
Debug,
MallocSizeOf,
PartialEq,
Parse,
SpecifiedValueInfo,
ToAnimatedValue,
ToAnimatedZero,
@ -35,19 +32,3 @@ impl<Url> UrlOrNone<Url> {
UrlOrNone::None
}
}
impl<Url> Parse for UrlOrNone<Url>
where
Url: Parse,
{
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<UrlOrNone<Url>, ParseError<'i>> {
if let Ok(url) = input.try(|input| Url::parse(context, input)) {
return Ok(UrlOrNone::Url(url));
}
input.expect_ident_matching("none")?;
Ok(UrlOrNone::None)
}
}