Derive ToComputedValue for Either<A, B>

This commit is contained in:
Anthony Ramine 2017-06-26 10:52:23 +02:00
parent 79ee821bef
commit 6c17bb03ce

View file

@ -52,7 +52,7 @@ impl Parse for Impossible {
/// A struct representing one of two kinds of values. /// A struct representing one of two kinds of values.
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Copy, HasViewportPercentage, PartialEq, ToCss)] #[derive(Clone, Copy, HasViewportPercentage, PartialEq, ToComputedValue, ToCss)]
pub enum Either<A, B> { pub enum Either<A, B> {
/// The first value. /// The first value.
First(A), First(A),
@ -80,27 +80,6 @@ impl<A: Parse, B: Parse> Parse for Either<A, B> {
} }
} }
use self::computed::{Context, ToComputedValue};
impl<A: ToComputedValue, B: ToComputedValue> ToComputedValue for Either<A, B> {
type ComputedValue = Either<A::ComputedValue, B::ComputedValue>;
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
match *self {
Either::First(ref a) => Either::First(a.to_computed_value(context)),
Either::Second(ref a) => Either::Second(a.to_computed_value(context)),
}
}
#[inline]
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
match *computed {
Either::First(ref a) => Either::First(ToComputedValue::from_computed_value(a)),
Either::Second(ref a) => Either::Second(ToComputedValue::from_computed_value(a)),
}
}
}
/// https://drafts.csswg.org/css-values-4/#custom-idents /// https://drafts.csswg.org/css-values-4/#custom-idents
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]