From c4cfb127b853849b4afce08ea0665d2f1f7da3de Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Mon, 5 Mar 2018 13:20:42 +0100 Subject: [PATCH] Use darling::util::Override in #[derive(ToCss)] --- components/style_derive/to_css.rs | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/components/style_derive/to_css.rs b/components/style_derive/to_css.rs index bd70aebf3ea..8864696fb9d 100644 --- a/components/style_derive/to_css.rs +++ b/components/style_derive/to_css.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use cg; -use darling::{Error, FromMetaItem}; +use darling::util::Override; use quote::Tokens; use syn::{self, Ident}; use synstructure; @@ -80,7 +80,7 @@ pub fn derive(input: syn::DeriveInput) -> Tokens { ::std::fmt::Write::write_str(dest, #identifier) } } else if let Some(function) = variant_attrs.function { - let mut identifier = function.name.map_or(identifier, |name| name.to_string()); + let mut identifier = function.explicit().map_or(identifier, |name| name.to_string()); identifier.push_str("("); expr = quote! { ::std::fmt::Write::write_str(dest, #identifier)?; @@ -129,7 +129,9 @@ pub fn derive(input: syn::DeriveInput) -> Tokens { #[derive(Default, FromDeriveInput)] struct CssInputAttrs { derive_debug: bool, - function: Option, + // Here because structs variants are also their whole type definition. + function: Option>, + // Here because structs variants are also their whole type definition. comma: bool, // Here because structs variants are also their whole type definition. iterable: bool, @@ -138,7 +140,7 @@ struct CssInputAttrs { #[darling(attributes(css), default)] #[derive(Default, FromVariant)] pub struct CssVariantAttrs { - pub function: Option, + pub function: Option>, pub iterable: bool, pub comma: bool, pub dimension: bool, @@ -151,18 +153,3 @@ pub struct CssVariantAttrs { struct CssFieldAttrs { ignore_bound: bool, } - -pub struct Function { - name: Option, -} - -impl FromMetaItem for Function { - fn from_word() -> Result { - Ok(Self { name: None }) - } - - fn from_string(name: &str) -> Result { - let name = Ident::from(name); - Ok(Self { name: Some(name) }) - } -}