mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Support #[animation(constant)] when deriving ToAnimatedZero
This commit is contained in:
parent
405e34aa74
commit
8101887d31
4 changed files with 23 additions and 31 deletions
|
@ -2,7 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use animate::AnimateAttrs;
|
||||
use animate::{AnimateAttrs, AnimateFieldAttrs};
|
||||
use cg;
|
||||
use quote;
|
||||
use syn;
|
||||
|
@ -25,10 +25,23 @@ pub fn derive(input: syn::DeriveInput) -> quote::Tokens {
|
|||
let bindings_pairs = bindings.into_iter().zip(mapped_bindings);
|
||||
let mut computations = quote!();
|
||||
computations.append_all(bindings_pairs.map(|(binding, mapped_binding)| {
|
||||
where_clause.add_trait_bound(binding.field.ty.clone());
|
||||
quote! {
|
||||
let #mapped_binding =
|
||||
::values::animated::ToAnimatedZero::to_animated_zero(#binding)?;
|
||||
let field_attrs = cg::parse_field_attrs::<AnimateFieldAttrs>(&binding.field);
|
||||
if field_attrs.constant {
|
||||
if cg::is_parameterized(&binding.field.ty, where_clause.params) {
|
||||
where_clause.inner.predicates.push(cg::where_predicate(
|
||||
binding.field.ty.clone(),
|
||||
&["std", "clone", "Clone"],
|
||||
));
|
||||
}
|
||||
quote! {
|
||||
let #mapped_binding = ::std::clone::Clone::clone(#binding);
|
||||
}
|
||||
} else {
|
||||
where_clause.add_trait_bound(binding.field.ty.clone());
|
||||
quote! {
|
||||
let #mapped_binding =
|
||||
::values::animated::ToAnimatedZero::to_animated_zero(#binding)?;
|
||||
}
|
||||
}
|
||||
}));
|
||||
computations.append(quote! { Ok(#mapped) });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue