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;
use animate::AnimationVariantAttrs;
use cg;
use quote;
use syn;
@ -17,7 +17,7 @@ pub fn derive(input: syn::DeriveInput) -> quote::Tokens {
let mut match_body = quote!();
let mut append_error_clause = variants.len() > 1;
match_body.append_all(variants.iter().map(|variant| {
let attrs = cg::parse_variant_attrs::<AnimateAttrs>(variant);
let attrs = cg::parse_variant_attrs::<AnimationVariantAttrs>(variant);
if attrs.error {
append_error_clause = true;
return None;