Implement #[animate(fallback)] for #[derive(Animate)]

This allows us to derive the Animate trait, providing a fallback function
for when the 2 values aren't similar.
This commit is contained in:
Anthony Ramine 2017-08-26 16:25:28 +02:00
parent 3751fe9fdc
commit 4a4bf89575
7 changed files with 99 additions and 121 deletions

View file

@ -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, AnimateFieldAttrs};
use animate::{AnimationVariantAttrs, AnimationFieldAttrs};
use cg;
use quote;
use syn;
@ -16,7 +16,7 @@ pub fn derive(input: syn::DeriveInput) -> quote::Tokens {
let bind_opts = BindStyle::Ref.into();
let to_body = synstructure::each_variant(&input, &bind_opts, |bindings, variant| {
let attrs = cg::parse_variant_attrs::<AnimateAttrs>(variant);
let attrs = cg::parse_variant_attrs::<AnimationVariantAttrs>(variant);
if attrs.error {
return Some(quote! { Err(()) });
}
@ -25,7 +25,7 @@ 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)| {
let field_attrs = cg::parse_field_attrs::<AnimateFieldAttrs>(&binding.field);
let field_attrs = cg::parse_field_attrs::<AnimationFieldAttrs>(&binding.field);
if field_attrs.constant {
if cg::is_parameterized(&binding.field.ty, where_clause.params, None) {
where_clause.inner.predicates.push(cg::where_predicate(