1use std::marker::PhantomData;
10
11use crate::{DynamicValues, IntoDynNode};
12use dioxus_core_template::TemplateRawTree;
13
14use super::{
15 DynamicNodeBuilder, DynamicViewChildMarker, IntoViewChild, View, ViewTemplate,
16 dynamic_node_builder,
17};
18
19struct StaticTupleViewChildMarker<T>(PhantomData<fn() -> T>);
20
21macro_rules! impl_tuple_views {
22 (($($name:ident $value:ident $marker:ident,)*) ;) => {};
23 (($($name:ident $value:ident $marker:ident,)*) ; $next_name:ident $next_value:ident $next_marker:ident, $($rest:tt)*) => {
24 impl_tuple_views!(@impl $($name $value $marker,)* $next_name $next_value $next_marker,);
25 impl_tuple_views!(($($name $value $marker,)* $next_name $next_value $next_marker,) ; $($rest)*);
26 };
27 (@impl $first_name:ident $first_value:ident $first_marker:ident,) => {
28 impl<$first_name: ViewTemplate> ViewTemplate for ($first_name,) {
29 const TEMPLATE_TREE: &'static TemplateRawTree = $first_name::TEMPLATE_TREE;
30 }
31
32 impl<$first_name: View> View for ($first_name,) {
33 #[inline]
34 fn push(self, dynamic: &mut DynamicValues) {
35 let ($first_value,) = self;
36 $first_value.push(dynamic);
37 }
38 }
39
40 };
41 (@impl $first_name:ident $first_value:ident $first_marker:ident, $($name:ident $value:ident $marker:ident,)+) => {
42 impl<$first_name: ViewTemplate, $($name: ViewTemplate),*> ViewTemplate for ($first_name, $($name,)*) {
43 const TEMPLATE_TREE: &'static TemplateRawTree =
44 &TemplateRawTree::Sequence(&[$first_name::TEMPLATE_TREE, $($name::TEMPLATE_TREE,)*]);
45 }
46
47 impl<$first_name: View, $($name: View),*> View for ($first_name, $($name,)*) {
48 #[inline]
49 fn push(self, dynamic: &mut DynamicValues) {
50 let ($first_value, $($value,)*) = self;
51 $first_value.push(dynamic);
52 $($value.push(dynamic);)*
53 }
54 }
55
56 };
57 (@impl_children ($($before_name:ident $before_value:ident,)*) ;) => {};
58 (@impl_children ($($before_name:ident $before_value:ident,)*) ; $dynamic_name:ident $dynamic_value:ident $dynamic_marker:ident, $($after_name:ident $after_value:ident $after_marker:ident,)*) => {
59 impl_tuple_views!(
60 @impl_child_at
61 ($($before_name $before_value,)*)
62 $dynamic_name $dynamic_value $dynamic_marker
63 ($($after_name $after_value $after_marker,)*)
64 );
65 impl_tuple_views!(
66 @impl_children
67 ($($before_name $before_value,)* $dynamic_name $dynamic_value,)
68 ;
69 $($after_name $after_value $after_marker,)*
70 );
71 };
72 (@impl_child_at ($($before_name:ident $before_value:ident,)*) $dynamic_name:ident $dynamic_value:ident $dynamic_marker:ident ($($after_name:ident $after_value:ident $after_marker:ident,)*)) => {
73 impl<$($before_name,)* $dynamic_name, $dynamic_marker, $($after_name, $after_marker),*>
74 IntoViewChild<($(
75 StaticTupleViewChildMarker<$before_name>,
76 )* DynamicViewChildMarker<$dynamic_marker>, $($after_marker,)*)>
77 for ($($before_name,)* $dynamic_name, $($after_name,)*)
78 where
79 $($before_name: View,)*
80 $dynamic_name: IntoDynNode<$dynamic_marker>,
81 $($after_name: IntoViewChild<$after_marker>),*
82 {
83 type Output = (
84 $($before_name,)*
85 DynamicNodeBuilder<$dynamic_name, $dynamic_marker>,
86 $(<$after_name as IntoViewChild<$after_marker>>::Output,)*
87 );
88
89 #[inline]
90 fn into_child(self) -> Self::Output {
91 let ($($before_value,)* $dynamic_value, $($after_value,)*) = self;
92 (
93 $($before_value,)*
94 dynamic_node_builder($dynamic_value),
95 $($after_value.into_child(),)*
96 )
97 }
98 }
99 };
100}
101
102macro_rules! impl_tuple_view_children {
103 (($($name:ident $value:ident $marker:ident,)*) ;) => {};
104 (($($name:ident $value:ident $marker:ident,)*) ; $next_name:ident $next_value:ident $next_marker:ident, $($rest:tt)*) => {
105 impl_tuple_views!(@impl_children () ; $($name $value $marker,)* $next_name $next_value $next_marker,);
106 impl_tuple_view_children!(($($name $value $marker,)* $next_name $next_value $next_marker,) ; $($rest)*);
107 };
108}
109
110impl_tuple_views! {
111 ();
112 T00 t00 M00,
113 T01 t01 M01,
114 T02 t02 M02,
115 T03 t03 M03,
116 T04 t04 M04,
117 T05 t05 M05,
118 T06 t06 M06,
119 T07 t07 M07,
120 T08 t08 M08,
121 T09 t09 M09,
122 T10 t10 M10,
123 T11 t11 M11,
124 T12 t12 M12,
125 T13 t13 M13,
126 T14 t14 M14,
127 T15 t15 M15,
128 T16 t16 M16,
129 T17 t17 M17,
130 T18 t18 M18,
131 T19 t19 M19,
132 T20 t20 M20,
133 T21 t21 M21,
134 T22 t22 M22,
135 T23 t23 M23,
136 T24 t24 M24,
137 T25 t25 M25,
138 T26 t26 M26,
139 T27 t27 M27,
140 T28 t28 M28,
141 T29 t29 M29,
142 T30 t30 M30,
143 T31 t31 M31,
144 T32 t32 M32,
145 T33 t33 M33,
146 T34 t34 M34,
147 T35 t35 M35,
148 T36 t36 M36,
149 T37 t37 M37,
150 T38 t38 M38,
151 T39 t39 M39,
152 T40 t40 M40,
153 T41 t41 M41,
154 T42 t42 M42,
155 T43 t43 M43,
156 T44 t44 M44,
157 T45 t45 M45,
158 T46 t46 M46,
159 T47 t47 M47,
160 T48 t48 M48,
161 T49 t49 M49,
162 T50 t50 M50,
163 T51 t51 M51,
164 T52 t52 M52,
165 T53 t53 M53,
166 T54 t54 M54,
167 T55 t55 M55,
168 T56 t56 M56,
169 T57 t57 M57,
170 T58 t58 M58,
171 T59 t59 M59,
172 T60 t60 M60,
173 T61 t61 M61,
174 T62 t62 M62,
175 T63 t63 M63,
176 T64 t64 M64,
177 T65 t65 M65,
178 T66 t66 M66,
179 T67 t67 M67,
180 T68 t68 M68,
181 T69 t69 M69,
182 T70 t70 M70,
183 T71 t71 M71,
184 T72 t72 M72,
185 T73 t73 M73,
186 T74 t74 M74,
187 T75 t75 M75,
188 T76 t76 M76,
189 T77 t77 M77,
190 T78 t78 M78,
191 T79 t79 M79,
192 T80 t80 M80,
193 T81 t81 M81,
194 T82 t82 M82,
195 T83 t83 M83,
196 T84 t84 M84,
197 T85 t85 M85,
198 T86 t86 M86,
199 T87 t87 M87,
200 T88 t88 M88,
201 T89 t89 M89,
202 T90 t90 M90,
203 T91 t91 M91,
204 T92 t92 M92,
205 T93 t93 M93,
206 T94 t94 M94,
207 T95 t95 M95,
208 T96 t96 M96,
209 T97 t97 M97,
210 T98 t98 M98,
211 T99 t99 M99,
212 T100 t100 M100,
213 T101 t101 M101,
214 T102 t102 M102,
215 T103 t103 M103,
216 T104 t104 M104,
217 T105 t105 M105,
218 T106 t106 M106,
219 T107 t107 M107,
220 T108 t108 M108,
221 T109 t109 M109,
222 T110 t110 M110,
223 T111 t111 M111,
224 T112 t112 M112,
225 T113 t113 M113,
226 T114 t114 M114,
227 T115 t115 M115,
228 T116 t116 M116,
229 T117 t117 M117,
230 T118 t118 M118,
231 T119 t119 M119,
232 T120 t120 M120,
233 T121 t121 M121,
234 T122 t122 M122,
235 T123 t123 M123,
236 T124 t124 M124,
237 T125 t125 M125,
238 T126 t126 M126,
239 T127 t127 M127,
240}
241
242impl_tuple_view_children! {
243 ();
244 T00 t00 M00,
245 T01 t01 M01,
246 T02 t02 M02,
247 T03 t03 M03,
248 T04 t04 M04,
249 T05 t05 M05,
250 T06 t06 M06,
251 T07 t07 M07,
252 T08 t08 M08,
253 T09 t09 M09,
254 T10 t10 M10,
255 T11 t11 M11,
256 T12 t12 M12,
257 T13 t13 M13,
258 T14 t14 M14,
259 T15 t15 M15,
260 T16 t16 M16,
261 T17 t17 M17,
262 T18 t18 M18,
263 T19 t19 M19,
264 T20 t20 M20,
265 T21 t21 M21,
266 T22 t22 M22,
267 T23 t23 M23,
268 T24 t24 M24,
269 T25 t25 M25,
270 T26 t26 M26,
271 T27 t27 M27,
272 T28 t28 M28,
273 T29 t29 M29,
274 T30 t30 M30,
275 T31 t31 M31,
276}