mirror of
https://github.com/servo/servo.git
synced 2025-08-09 07:25:35 +01:00
Simplify the derived bounds for ToAnimatedValue
This commit is contained in:
parent
664efab4a3
commit
92068ca540
2 changed files with 29 additions and 9 deletions
|
@ -126,7 +126,16 @@ pub fn fmap_trait_parts<'input, 'path>(
|
||||||
) -> (ImplGenerics<'input>, TypeGenerics<'input>, WhereClause<'input, 'path>, Path) {
|
) -> (ImplGenerics<'input>, TypeGenerics<'input>, WhereClause<'input, 'path>, Path) {
|
||||||
let (impl_generics, ty_generics, mut where_clause) = trait_parts(input, trait_path);
|
let (impl_generics, ty_generics, mut where_clause) = trait_parts(input, trait_path);
|
||||||
where_clause.trait_output = Some(trait_output);
|
where_clause.trait_output = Some(trait_output);
|
||||||
let output_ty = PathSegment {
|
let output_ty = fmap_trait_output(input, trait_path, trait_output);
|
||||||
|
(impl_generics, ty_generics, where_clause, output_ty)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn fmap_trait_output(
|
||||||
|
input: &DeriveInput,
|
||||||
|
trait_path: &Path,
|
||||||
|
trait_output: Ident,
|
||||||
|
) -> Path {
|
||||||
|
let segment = PathSegment {
|
||||||
ident: input.ident.clone(),
|
ident: input.ident.clone(),
|
||||||
arguments: PathArguments::AngleBracketed(AngleBracketedGenericArguments {
|
arguments: PathArguments::AngleBracketed(AngleBracketedGenericArguments {
|
||||||
args: input.generics.params.iter().map(|arg| {
|
args: input.generics.params.iter().map(|arg| {
|
||||||
|
@ -151,7 +160,7 @@ pub fn fmap_trait_parts<'input, 'path>(
|
||||||
|
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
(impl_generics, ty_generics, where_clause, output_ty.into())
|
segment.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_parameterized(
|
pub fn is_parameterized(
|
||||||
|
|
|
@ -4,23 +4,34 @@
|
||||||
|
|
||||||
use cg;
|
use cg;
|
||||||
use quote;
|
use quote;
|
||||||
use syn::{self, Ident};
|
use syn::DeriveInput;
|
||||||
use synstructure::BindStyle;
|
use synstructure::BindStyle;
|
||||||
|
|
||||||
pub fn derive(input: syn::DeriveInput) -> quote::Tokens {
|
pub fn derive(mut input: DeriveInput) -> quote::Tokens {
|
||||||
let name = &input.ident;
|
let mut where_clause = input.generics.where_clause.take();
|
||||||
let trait_path = parse_quote!(values::animated::ToAnimatedValue);
|
for param in input.generics.type_params() {
|
||||||
let (impl_generics, ty_generics, mut where_clause, animated_value_type) =
|
cg::add_predicate(
|
||||||
cg::fmap_trait_parts(&input, &trait_path, Ident::from("AnimatedValue"));
|
&mut where_clause,
|
||||||
|
parse_quote!(#param: ::values::animated::ToAnimatedValue),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
input.generics.where_clause = where_clause;
|
||||||
|
|
||||||
let to_body = cg::fmap_match(&input, BindStyle::Move, |binding| {
|
let to_body = cg::fmap_match(&input, BindStyle::Move, |binding| {
|
||||||
where_clause.add_trait_bound(&binding.ast().ty);
|
|
||||||
quote!(::values::animated::ToAnimatedValue::to_animated_value(#binding))
|
quote!(::values::animated::ToAnimatedValue::to_animated_value(#binding))
|
||||||
});
|
});
|
||||||
let from_body = cg::fmap_match(&input, BindStyle::Move, |binding| {
|
let from_body = cg::fmap_match(&input, BindStyle::Move, |binding| {
|
||||||
quote!(::values::animated::ToAnimatedValue::from_animated_value(#binding))
|
quote!(::values::animated::ToAnimatedValue::from_animated_value(#binding))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let name = &input.ident;
|
||||||
|
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
|
||||||
|
let animated_value_type = cg::fmap_trait_output(
|
||||||
|
&input,
|
||||||
|
&parse_quote!(values::animated::ToAnimatedValue),
|
||||||
|
"AnimatedValue".into(),
|
||||||
|
);
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
impl #impl_generics ::values::animated::ToAnimatedValue for #name #ty_generics #where_clause {
|
impl #impl_generics ::values::animated::ToAnimatedValue for #name #ty_generics #where_clause {
|
||||||
type AnimatedValue = #animated_value_type;
|
type AnimatedValue = #animated_value_type;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue