Refactor how we handle trait bounds in style_derive

For the traits we derive which methods don't depend on associated types (i.e.
all of them but ToAnimatedValue and ToComputedValue), we now add trait bounds
for the actual field types directly, instead of bounding the type parameters.
This commit is contained in:
Anthony Ramine 2017-08-25 19:58:49 +02:00
parent 13d47ba69a
commit 04ad28b564
8 changed files with 75 additions and 58 deletions

View file

@ -9,13 +9,13 @@ use synstructure::BindStyle;
pub fn derive(input: syn::DeriveInput) -> quote::Tokens {
let name = &input.ident;
let (impl_generics, ty_generics, where_clause) = cg::trait_parts(
&input,
&["values", "animated", "ToAnimatedZero"],
);
let trait_path = &["values", "animated", "ToAnimatedZero"];
let (impl_generics, ty_generics, mut where_clause) =
cg::trait_parts(&input, trait_path);
let to_body = cg::fmap_match(&input, BindStyle::Ref, |field| {
quote! { ::values::animated::ToAnimatedZero::to_animated_zero(#field)? }
let to_body = cg::fmap_match(&input, BindStyle::Ref, |binding| {
where_clause.add_trait_bound(binding.field.ty.clone());
quote! { ::values::animated::ToAnimatedZero::to_animated_zero(#binding)? }
});
quote! {