Make Interpolate impl generic for Either

This commit is contained in:
Xidorn Quan 2017-03-17 17:52:43 +11:00
parent 0d556ddbf0
commit b489c4ed90

View file

@ -34,7 +34,6 @@ use values::computed::{Angle, LengthOrPercentageOrAuto, LengthOrPercentageOrNone
use values::computed::{BorderRadiusSize, ClipRect, LengthOrNone};
use values::computed::{CalcLengthOrPercentage, Context, LengthOrPercentage};
use values::computed::{MaxLength, MinLength};
use values::computed::ColorOrAuto;
use values::computed::position::{HorizontalPosition, Position, VerticalPosition};
use values::computed::ToComputedValue;
use values::specified::Angle as SpecifiedAngle;
@ -399,6 +398,13 @@ impl Interpolate for Au {
}
}
impl Interpolate for Auto {
#[inline]
fn interpolate(&self, _other: &Self, _progress: f64) -> Result<Self, ()> {
Ok(Auto)
}
}
impl <T> Interpolate for Option<T>
where T: Interpolate,
{
@ -1832,16 +1838,17 @@ impl Interpolate for TransformList {
}
}
/// https://drafts.csswg.org/css-transitions-1/#animtype-color
impl Interpolate for ColorOrAuto {
impl<T, U> Interpolate for Either<T, U>
where T: Interpolate + Copy, U: Interpolate + Copy,
{
#[inline]
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
match (*self, *other) {
(Either::First(ref this), Either::First(ref other)) => {
this.interpolate(&other, progress).map(Either::First)
},
(Either::Second(Auto), Either::Second(Auto)) => {
Ok(Either::Second(Auto))
(Either::Second(ref this), Either::Second(ref other)) => {
this.interpolate(&other, progress).map(Either::Second)
},
_ => {
let interpolated = if progress < 0.5 { *self } else { *other };