tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

to_animated_value.rs (1487B)


      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 
      5 use crate::animate::AnimationFieldAttrs;
      6 use crate::{cg, to_computed_value};
      7 use proc_macro2::TokenStream;
      8 use syn::DeriveInput;
      9 use synstructure::BindStyle;
     10 
     11 pub fn derive(input: DeriveInput) -> TokenStream {
     12    let trait_impl = |from_body, to_body| {
     13        quote! {
     14             #[inline]
     15             fn from_animated_value(from: Self::AnimatedValue) -> Self {
     16                 #from_body
     17             }
     18 
     19             #[inline]
     20             fn to_animated_value(self, context: &crate::values::animated::Context) -> Self::AnimatedValue {
     21                 #to_body
     22             }
     23        }
     24    };
     25 
     26    to_computed_value::derive_to_value(
     27        input,
     28        parse_quote!(crate::values::animated::ToAnimatedValue),
     29        parse_quote!(AnimatedValue),
     30        BindStyle::Move,
     31        |binding| {
     32            let attrs = cg::parse_field_attrs::<AnimationFieldAttrs>(&binding.ast());
     33            to_computed_value::ToValueAttrs {
     34                field_bound: attrs.field_bound,
     35                no_field_bound: false,
     36            }
     37        },
     38        |binding| quote!(crate::values::animated::ToAnimatedValue::from_animated_value(#binding)),
     39        |binding| quote!(crate::values::animated::ToAnimatedValue::to_animated_value(#binding, context)),
     40        trait_impl,
     41    )
     42 }