Skip to content

Commit 6d35252

Browse files
committed
servo: Merge #16478 - Support non-negative parsing of lengths for Either<Length, T> types (from yashmehrotra:fix-16423); r=Wafflespeanut
<!-- Please describe your changes on the following line: --> Implemented a generic `impl<T> Either<Length, T>` which has a `parse_non_negative_length` method. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #16423 <!-- Either: --> - [x] These changes do not require tests because this functionality makes code more modular and doesn't change any existing implementation. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 91bd8f44f2bf373921a8453d4a9732f22d8ee344
1 parent 9eb8b79 commit 6d35252

File tree

1 file changed

+4
-26
lines changed
  • servo/components/style/values/specified

1 file changed

+4
-26
lines changed

servo/components/style/values/specified/length.rs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -592,34 +592,12 @@ impl Parse for Length {
592592
}
593593
}
594594

595-
impl Either<Length, None_> {
596-
/// Parse a non-negative length or none
597-
#[inline]
598-
pub fn parse_non_negative_length(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
599-
if input.try(|input| None_::parse(context, input)).is_ok() {
600-
return Ok(Either::Second(None_));
601-
}
602-
Length::parse_non_negative(context, input).map(Either::First)
603-
}
604-
}
605-
606-
impl Either<Length, Normal> {
607-
#[inline]
608-
#[allow(missing_docs)]
609-
pub fn parse_non_negative_length(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
610-
if input.try(|input| Normal::parse(context, input)).is_ok() {
611-
return Ok(Either::Second(Normal));
612-
}
613-
Length::parse_internal(context, input, AllowedLengthType::NonNegative).map(Either::First)
614-
}
615-
}
616-
617-
impl Either<Length, Auto> {
595+
impl<T: Parse> Either<Length, T> {
596+
/// Parse a non-negative length
618597
#[inline]
619-
#[allow(missing_docs)]
620598
pub fn parse_non_negative_length(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
621-
if input.try(|input| Auto::parse(context, input)).is_ok() {
622-
return Ok(Either::Second(Auto));
599+
if let Ok(v) = input.try(|input| T::parse(context, input)) {
600+
return Ok(Either::Second(v));
623601
}
624602
Length::parse_internal(context, input, AllowedLengthType::NonNegative).map(Either::First)
625603
}

0 commit comments

Comments
 (0)