reactive_graph_graph/instances/properties/
property.rs

1#[macro_export]
2macro_rules! properties {
3    (
4        /// The ident of the properties model.
5        $properties: ident
6        $(,
7            (
8                /// The ident of the property.
9                $property_ident: ident,
10
11                /// The name for serialization.
12                $property_name: expr,
13
14                /// The default value.
15                $property_default_value: expr
16            )
17        )*
18    ) => {
19        #[allow(non_camel_case_types)]
20        #[derive(strum_macros::AsRefStr, strum_macros::IntoStaticStr, strum_macros::Display)]
21        pub enum $properties {
22            $(
23                #[strum(serialize = $property_name)]
24                $property_ident,
25            )*
26        }
27
28        impl $crate::PropertyTypeDefinition for $properties {
29            fn property_name(&self) -> String {
30                self.as_ref().into()
31            }
32
33            fn default_value(&self) -> serde_json::Value {
34                match self {
35                    $(
36                        $properties::$property_ident => serde_json::json!($property_default_value),
37                    )*
38                }
39            }
40        }
41
42        impl From<$properties> for String {
43            fn from(p: $properties) -> Self {
44                p.to_string()
45            }
46        }
47    };
48}