stylo_derive/
to_animated_value.rs1use crate::to_computed_value;
6use proc_macro2::TokenStream;
7use syn::DeriveInput;
8use synstructure::BindStyle;
9
10pub fn derive(input: DeriveInput) -> TokenStream {
11 let trait_impl = |from_body, to_body| {
12 quote! {
13 #[inline]
14 fn from_animated_value(from: Self::AnimatedValue) -> Self {
15 #from_body
16 }
17
18 #[inline]
19 fn to_animated_value(self, context: &crate::values::animated::Context) -> Self::AnimatedValue {
20 #to_body
21 }
22 }
23 };
24
25 to_computed_value::derive_to_value(
26 input,
27 parse_quote!(crate::values::animated::ToAnimatedValue),
28 parse_quote!(AnimatedValue),
29 BindStyle::Move,
30 |_| Default::default(),
31 |binding| quote!(crate::values::animated::ToAnimatedValue::from_animated_value(#binding)),
32 |binding| quote!(crate::values::animated::ToAnimatedValue::to_animated_value(#binding, context)),
33 trait_impl,
34 )
35}