From b9f5388635844033b9a3f3386ac7cf7dd61bd1e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 9 Sep 2017 13:18:50 +0200 Subject: [PATCH] style: Use derive for -x-span. --- components/style/macros.rs | 30 ++++++++++++------- .../style/properties/longhand/table.mako.rs | 11 ++++--- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/components/style/macros.rs b/components/style/macros.rs index 503c13ba283..bdbaaab5dbe 100644 --- a/components/style/macros.rs +++ b/components/style/macros.rs @@ -4,6 +4,24 @@ //! Various macro helpers. +macro_rules! trivial_to_computed_value { + ($name: ident) => { + impl $crate::values::computed::ToComputedValue for $name { + type ComputedValue = $name; + + fn to_computed_value(&self, _: &$crate::values::computed::Context) -> Self { + self.clone() + } + + fn from_computed_value(other: &Self) -> Self { + other.clone() + } + } + } +} + +trivial_to_computed_value!(i32); + /// A macro to parse an identifier, or return an `UnexpectedIndent` error /// otherwise. /// @@ -76,17 +94,7 @@ macro_rules! add_impls_for_keyword_enum { } } - impl $crate::values::computed::ToComputedValue for $name { - type ComputedValue = $name; - - fn to_computed_value(&self, _: &$crate::values::computed::Context) -> Self { - self.clone() - } - - fn from_computed_value(other: &Self) -> Self { - other.clone() - } - } + trivial_to_computed_value!($name); }; } diff --git a/components/style/properties/longhand/table.mako.rs b/components/style/properties/longhand/table.mako.rs index 68f40e22d37..5cc753b38ab 100644 --- a/components/style/properties/longhand/table.mako.rs +++ b/components/style/properties/longhand/table.mako.rs @@ -14,15 +14,12 @@ ${helpers.single_keyword("table-layout", "auto fixed", spec="Internal-only (for `` pres attr)" animation_value_type="none" internal="True"> - use values::computed::ComputedValueAsSpecified; - - impl ComputedValueAsSpecified for SpecifiedValue {} pub type SpecifiedValue = computed_value::T; pub mod computed_value { use std::fmt; use style_traits::ToCss; - #[derive(Clone, Copy, Debug, PartialEq)] + #[derive(Clone, Copy, Debug, PartialEq, ToComputedValue)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] pub struct T(pub i32); @@ -39,8 +36,10 @@ ${helpers.single_keyword("table-layout", "auto fixed", } // never parse it, only set via presentation attribute - fn parse<'i, 't>(_: &ParserContext, _: &mut Parser<'i, 't>) - -> Result> { + fn parse<'i, 't>( + _: &ParserContext, + _: &mut Parser<'i, 't>, + ) -> Result> { Err(StyleParseError::UnspecifiedError.into()) }