mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
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:
parent
13d47ba69a
commit
04ad28b564
8 changed files with 75 additions and 58 deletions
|
@ -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! {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue