Auto merge of #14296 - Wafflespeanut:either, r=emilio

Some generic impls for Either<Length, T>

<!-- Please describe your changes on the following line: -->

We seem to be using `parse_non_negative` a lot for `LengthOrFoo` types, so it's better to have generic impls (now, and in the future) for such things (assuming that `Length` will always be in the first variant of `Either`).

---
<!-- 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

<!-- Either: -->
- [x] These changes do not require tests because it's a refactor

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14296)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-11-22 14:59:11 -06:00 committed by GitHub
commit bcf4184483

View file

@ -343,6 +343,13 @@ impl Parse for Length {
} }
} }
impl<T> Either<Length, T> {
#[inline]
pub fn parse_non_negative_length(input: &mut Parser) -> Result<Either<Length, T>, ()> {
Length::parse_internal(input, AllowedNumericType::NonNegative).map(Either::First)
}
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct CalcSumNode { pub struct CalcSumNode {
pub products: Vec<CalcProductNode>, pub products: Vec<CalcProductNode>,
@ -946,13 +953,6 @@ impl Parse for LengthOrPercentageOrNone {
pub type LengthOrNone = Either<Length, None_>; pub type LengthOrNone = Either<Length, None_>;
impl LengthOrNone {
#[inline]
pub fn parse_non_negative(input: &mut Parser) -> Result<LengthOrNone, ()> {
Length::parse_internal(input, AllowedNumericType::NonNegative).map(Either::First)
}
}
#[derive(Clone, PartialEq, Copy, Debug)] #[derive(Clone, PartialEq, Copy, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum LengthOrPercentageOrAutoOrContent { pub enum LengthOrPercentageOrAutoOrContent {