mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: add css(function, iterable), and derive ToCss for VariantAlternates.
This commit is contained in:
parent
33fa728d6e
commit
06f8f0384b
2 changed files with 25 additions and 60 deletions
|
@ -21,13 +21,27 @@ pub fn derive(input: DeriveInput) -> Tokens {
|
|||
let separator = if variant_attrs.comma { ", " } else { " " };
|
||||
let mut expr = if !bindings.is_empty() {
|
||||
let mut expr = quote! {};
|
||||
for binding in bindings {
|
||||
where_clause.add_trait_bound(&binding.field.ty);
|
||||
|
||||
if variant_attrs.function && variant_attrs.iterable {
|
||||
assert_eq!(bindings.len(), 1);
|
||||
let binding = &bindings[0];
|
||||
expr = quote! {
|
||||
#expr
|
||||
writer.item(#binding)?;
|
||||
|
||||
for item in #binding.iter() {
|
||||
writer.item(item)?;
|
||||
}
|
||||
};
|
||||
} else {
|
||||
for binding in bindings {
|
||||
where_clause.add_trait_bound(&binding.field.ty);
|
||||
expr = quote! {
|
||||
#expr
|
||||
writer.item(#binding)?;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
quote! {{
|
||||
let mut writer = ::style_traits::values::SequenceWriter::new(&mut *dest, #separator);
|
||||
#expr
|
||||
|
@ -89,6 +103,7 @@ struct CssInputAttrs {
|
|||
#[derive(Default, FromVariant)]
|
||||
struct CssVariantAttrs {
|
||||
function: bool,
|
||||
iterable: bool,
|
||||
comma: bool,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue