reactive_graph_reactive_model_api/
relation.rs

1#[macro_export]
2macro_rules! relation_model {
3    (
4        $ident: ident
5        $(,
6            $accessor_type: tt
7            $(
8            $accessor_name: ident
9            $accessor_data_type: tt
10            )?
11        )*
12        $(,)?
13    ) => {
14        pub struct $ident(reactive_graph_reactive_model_impl::ReactiveRelation);
15
16        impl $ident {
17            $(
18                reactive_graph_graph::rx_accessor!(pub $accessor_type $($accessor_name $accessor_data_type)?);
19            )*
20        }
21
22        impl $crate::ReactiveInstanceGetter<reactive_graph_reactive_model_impl::ReactiveRelation> for $ident {
23            fn get_reactive_instance(&self) -> &reactive_graph_reactive_model_impl::ReactiveRelation {
24                &self.0
25            }
26        }
27
28        impl From<reactive_graph_reactive_model_impl::ReactiveRelation> for $ident {
29            fn from(reactive_relation: reactive_graph_reactive_model_impl::ReactiveRelation) -> Self {
30                $ident(reactive_relation)
31            }
32        }
33
34        impl reactive_graph_graph::PropertyInstanceGetter for $ident {
35            fn get<S: Into<String>>(&self, property_name: S) -> Option<serde_json::Value> {
36                self.0.get(property_name)
37            }
38
39            fn as_bool<S: Into<String>>(&self, property_name: S) -> Option<bool> {
40                self.0.as_bool(property_name)
41            }
42
43            fn as_u64<S: Into<String>>(&self, property_name: S) -> Option<u64> {
44                self.0.as_u64(property_name)
45            }
46
47            fn as_i64<S: Into<String>>(&self, property_name: S) -> Option<i64> {
48                self.0.as_i64(property_name)
49            }
50
51            fn as_f64<S: Into<String>>(&self, property_name: S) -> Option<f64> {
52                self.0.as_f64(property_name)
53            }
54
55            fn as_string<S: Into<String>>(&self, property_name: S) -> Option<String> {
56                self.0.as_string(property_name)
57            }
58
59            fn as_array<S: Into<String>>(&self, property_name: S) -> Option<Vec<serde_json::Value>> {
60                self.0.as_array(property_name)
61            }
62
63            fn as_object<S: Into<String>>(&self, property_name: S) -> Option<serde_json::Map<String, serde_json::Value>> {
64                self.0.as_object(property_name)
65            }
66        }
67
68        impl reactive_graph_graph::PropertyInstanceSetter for $ident {
69            fn set_checked<S: Into<String>>(&self, property_name: S, value: serde_json::Value) {
70                self.0.set_checked(property_name, value);
71            }
72
73            fn set<S: Into<String>>(&self, property_name: S, value: serde_json::Value) {
74                self.0.set(property_name, value);
75            }
76
77            fn set_no_propagate_checked<S: Into<String>>(&self, property_name: S, value: serde_json::Value) {
78                self.0.set_no_propagate_checked(property_name, value);
79            }
80
81            fn set_no_propagate<S: Into<String>>(&self, property_name: S, value: serde_json::Value) {
82                self.0.set_no_propagate(property_name, value);
83            }
84
85            fn mutability<S: Into<String>>(&self, property_name: S) -> Option<reactive_graph_graph::Mutability> {
86                self.0.mutability(property_name)
87            }
88
89            fn set_mutability<S: Into<String>>(&self, property_name: S, mutability: reactive_graph_graph::Mutability) {
90                self.0.set_mutability(property_name, mutability);
91            }
92        }
93
94        impl reactive_graph_graph::NamespacedTypeGetter for $ident {
95            fn namespace(&self) -> String {
96                self.0.ty.namespace()
97            }
98
99            fn type_name(&self) -> String {
100                self.0.ty.type_name()
101            }
102        }
103
104        impl reactive_graph_graph::TypeDefinitionGetter for $ident {
105            fn type_definition(&self) -> reactive_graph_graph::TypeDefinition {
106                self.0.ty.type_definition()
107            }
108        }
109
110        impl std::fmt::Display for $ident {
111            fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
112                write!(f, "{}", &self.0)
113            }
114        }
115    };
116}