Auto merge of #14261 - Wafflespeanut:lon, r=SimonSapin

Prefer Either type for LengthOrNumber

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

This adds `impl GeckoStyleCoordConvertible for Either<A, B>` and makes `LengthOrNumber` prefer `Either<A, B>`.

---
<!-- 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 build-geckolib` 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. -->

r? @SimonSapin

<!-- 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/14261)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-11-18 22:20:04 -06:00 committed by GitHub
commit 0c55d461f1
4 changed files with 36 additions and 110 deletions

View file

@ -1008,40 +1008,4 @@ impl Parse for LengthOrPercentageOrAutoOrContent {
}
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum LengthOrNumber {
Length(Length),
Number(Number),
}
impl HasViewportPercentage for LengthOrNumber {
fn has_viewport_percentage(&self) -> bool {
match *self {
LengthOrNumber::Length(length) => length.has_viewport_percentage(),
_ => false
}
}
}
impl ToCss for LengthOrNumber {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
LengthOrNumber::Length(len) => len.to_css(dest),
LengthOrNumber::Number(number) => number.to_css(dest),
}
}
}
impl Parse for LengthOrNumber {
fn parse(input: &mut Parser) -> Result<Self, ()> {
let length = input.try(Length::parse);
if let Ok(len) = length {
return Ok(LengthOrNumber::Length(len));
}
let num = try!(Number::parse_non_negative(input));
Ok(LengthOrNumber::Number(num))
}
}
pub type LengthOrNumber = Either<Length, Number>;