stylo_derive/
to_animated_value.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use 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}