mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
Improve handling of trait bounds when deriving fmap-like traits
This commit is contained in:
parent
8101887d31
commit
efc852f6e3
12 changed files with 229 additions and 136 deletions
|
@ -3,26 +3,26 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use cg;
|
||||
use quote;
|
||||
use syn;
|
||||
use quote::Tokens;
|
||||
use syn::DeriveInput;
|
||||
use synstructure::BindStyle;
|
||||
|
||||
pub fn derive(input: syn::DeriveInput) -> quote::Tokens {
|
||||
pub fn derive(input: DeriveInput) -> Tokens {
|
||||
let name = &input.ident;
|
||||
let trait_path = &["values", "computed", "ToComputedValue"];
|
||||
let (impl_generics, ty_generics, mut where_clause, computed_value_type) =
|
||||
cg::fmap_trait_parts(&input, trait_path, "ComputedValue");
|
||||
for param in &input.generics.ty_params {
|
||||
where_clause.add_trait_bound(
|
||||
syn::Ty::Path(None, param.ident.clone().into()),
|
||||
);
|
||||
}
|
||||
|
||||
let to_body = cg::fmap_match(&input, BindStyle::Ref, |binding| {
|
||||
quote!(::values::computed::ToComputedValue::to_computed_value(#binding, context))
|
||||
where_clause.add_trait_bound(&binding.field.ty);
|
||||
quote! {
|
||||
::values::computed::ToComputedValue::to_computed_value(#binding, context)
|
||||
}
|
||||
});
|
||||
let from_body = cg::fmap_match(&input, BindStyle::Ref, |binding| {
|
||||
quote!(::values::computed::ToComputedValue::from_computed_value(#binding))
|
||||
quote! {
|
||||
::values::computed::ToComputedValue::from_computed_value(#binding)
|
||||
}
|
||||
});
|
||||
|
||||
quote! {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue