mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
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:
parent
6118e4d993
commit
73d5b82f9f
24 changed files with 238 additions and 362 deletions
|
@ -305,7 +305,7 @@ impl Gradient {
|
|||
) -> Result<Self, ParseError<'i>> {
|
||||
type Point = GenericPosition<Component<X>, Component<Y>>;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, Parse)]
|
||||
enum Component<S> {
|
||||
Center,
|
||||
Number(NumberOrPercentage),
|
||||
|
@ -408,22 +408,6 @@ impl Gradient {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S: Parse> Parse for Component<S> {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(side) = input.try(|i| S::parse(context, i)) {
|
||||
return Ok(Component::Side(side));
|
||||
}
|
||||
if let Ok(number) = input.try(|i| NumberOrPercentage::parse(context, i)) {
|
||||
return Ok(Component::Number(number));
|
||||
}
|
||||
input.try(|i| i.expect_ident_matching("center"))?;
|
||||
Ok(Component::Center)
|
||||
}
|
||||
}
|
||||
|
||||
let ident = input.expect_ident_cloned()?;
|
||||
input.expect_comma()?;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue