Skip to main content

rustmotion_core/
macros.rs

1#[macro_export]
2macro_rules! impl_traits {
3    ($type:ty { $($trait_name:ident => $field:ident),* $(,)? }) => {
4        $(
5            $crate::impl_traits!(@single $type, $trait_name, $field);
6        )*
7    };
8
9    (@single $type:ty, Animatable, $_field:ident) => {
10        impl $crate::traits::Animatable for $type {
11            fn animation_effects(&self) -> &[$crate::schema::AnimationEffect] {
12                &self.style.animation
13            }
14
15            fn timeline_steps(&self) -> &[$crate::schema::TimelineStep] {
16                &self.timeline
17            }
18        }
19    };
20
21    (@single $type:ty, Timed, $field:ident) => {
22        impl $crate::traits::Timed for $type {
23            fn timing(&self) -> (Option<f64>, Option<f64>) {
24                (self.$field.start_at, self.$field.end_at)
25            }
26        }
27    };
28
29    (@single $type:ty, Styled, $field:ident) => {
30        impl $crate::traits::Styled for $type {
31            fn style_config(&self) -> &$crate::css::CssStyle {
32                &self.$field
33            }
34        }
35
36        impl $crate::traits::StyledMut for $type {
37            fn style_config_mut(&mut self) -> &mut $crate::css::CssStyle {
38                &mut self.$field
39            }
40        }
41    };
42}