mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Auto merge of #20198 - servo:derive-all-the-things, r=emilio
Use darling::util::Override in #[derive(ToCss)] <!-- 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/20198) <!-- Reviewable:end -->
This commit is contained in:
commit
7931df716d
1 changed files with 6 additions and 19 deletions
|
@ -3,7 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use cg;
|
use cg;
|
||||||
use darling::{Error, FromMetaItem};
|
use darling::util::Override;
|
||||||
use quote::Tokens;
|
use quote::Tokens;
|
||||||
use syn::{self, Ident};
|
use syn::{self, Ident};
|
||||||
use synstructure;
|
use synstructure;
|
||||||
|
@ -80,7 +80,7 @@ pub fn derive(input: syn::DeriveInput) -> Tokens {
|
||||||
::std::fmt::Write::write_str(dest, #identifier)
|
::std::fmt::Write::write_str(dest, #identifier)
|
||||||
}
|
}
|
||||||
} else if let Some(function) = variant_attrs.function {
|
} 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("(");
|
identifier.push_str("(");
|
||||||
expr = quote! {
|
expr = quote! {
|
||||||
::std::fmt::Write::write_str(dest, #identifier)?;
|
::std::fmt::Write::write_str(dest, #identifier)?;
|
||||||
|
@ -129,7 +129,9 @@ pub fn derive(input: syn::DeriveInput) -> Tokens {
|
||||||
#[derive(Default, FromDeriveInput)]
|
#[derive(Default, FromDeriveInput)]
|
||||||
struct CssInputAttrs {
|
struct CssInputAttrs {
|
||||||
derive_debug: bool,
|
derive_debug: bool,
|
||||||
function: Option<Function>,
|
// Here because structs variants are also their whole type definition.
|
||||||
|
function: Option<Override<Ident>>,
|
||||||
|
// Here because structs variants are also their whole type definition.
|
||||||
comma: bool,
|
comma: bool,
|
||||||
// Here because structs variants are also their whole type definition.
|
// Here because structs variants are also their whole type definition.
|
||||||
iterable: bool,
|
iterable: bool,
|
||||||
|
@ -138,7 +140,7 @@ struct CssInputAttrs {
|
||||||
#[darling(attributes(css), default)]
|
#[darling(attributes(css), default)]
|
||||||
#[derive(Default, FromVariant)]
|
#[derive(Default, FromVariant)]
|
||||||
pub struct CssVariantAttrs {
|
pub struct CssVariantAttrs {
|
||||||
pub function: Option<Function>,
|
pub function: Option<Override<Ident>>,
|
||||||
pub iterable: bool,
|
pub iterable: bool,
|
||||||
pub comma: bool,
|
pub comma: bool,
|
||||||
pub dimension: bool,
|
pub dimension: bool,
|
||||||
|
@ -151,18 +153,3 @@ pub struct CssVariantAttrs {
|
||||||
struct CssFieldAttrs {
|
struct CssFieldAttrs {
|
||||||
ignore_bound: bool,
|
ignore_bound: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Function {
|
|
||||||
name: Option<Ident>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromMetaItem for Function {
|
|
||||||
fn from_word() -> Result<Self, Error> {
|
|
||||||
Ok(Self { name: None })
|
|
||||||
}
|
|
||||||
|
|
||||||
fn from_string(name: &str) -> Result<Self, Error> {
|
|
||||||
let name = Ident::from(name);
|
|
||||||
Ok(Self { name: Some(name) })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue