From de84a89827ef9450fca0d36e77446d4cf2a42ef4 Mon Sep 17 00:00:00 2001 From: Yash Mehrotra Date: Sun, 16 Apr 2017 09:19:00 +0530 Subject: [PATCH] Support non-negative parsing of lengths for Either types --- components/style/values/specified/length.rs | 30 +++------------------ 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 2b75201e0a0..5547234371e 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -587,34 +587,12 @@ impl Parse for Length { } } -impl Either { - /// Parse a non-negative length or none +impl Either { + /// Parse a non-negative length #[inline] pub fn parse_non_negative_length(context: &ParserContext, input: &mut Parser) -> Result { - if input.try(|input| None_::parse(context, input)).is_ok() { - return Ok(Either::Second(None_)); - } - Length::parse_non_negative(context, input).map(Either::First) - } -} - -impl Either { - #[inline] - #[allow(missing_docs)] - pub fn parse_non_negative_length(context: &ParserContext, input: &mut Parser) -> Result { - if input.try(|input| Normal::parse(context, input)).is_ok() { - return Ok(Either::Second(Normal)); - } - Length::parse_internal(context, input, AllowedLengthType::NonNegative).map(Either::First) - } -} - -impl Either { - #[inline] - #[allow(missing_docs)] - pub fn parse_non_negative_length(context: &ParserContext, input: &mut Parser) -> Result { - if input.try(|input| Auto::parse(context, input)).is_ok() { - return Ok(Either::Second(Auto)); + if let Ok(v) = input.try(|input| T::parse(context, input)) { + return Ok(Either::Second(v)); } Length::parse_internal(context, input, AllowedLengthType::NonNegative).map(Either::First) }