1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
use crateComponent;
use crate;
use crateWidthConstraint;
// ---------------------------------------------------------------------------
// AddTo — how a value adds itself to a collector
// ---------------------------------------------------------------------------
/// Trait for adding a value to a child collector.
///
/// The `element!` macro dispatches all child additions through this trait,
/// enabling **compile-time type checking** of parent-child relationships.
/// If you try to nest a component inside a parent that doesn't accept it,
/// you'll get a compile error rather than a runtime panic.
///
/// # Implementations
///
/// - **Blanket impl**: any [`Component`] can be added to [`Elements`].
/// - **Data types**: [`Span`](crate::Span) converts `Into<TextChild>`,
/// `String` converts `Into<TextChild>`. These produce compile errors
/// if used in the wrong context.
/// Blanket: any Component can be added to Elements.
/// String → Elements: creates a Text component with the string as content.
///
/// This powers the `element!` string literal sugar — `"hello"` becomes a
/// [`Text`](crate::Text) component. The same `AddTo` dispatch also works
/// inside data children contexts (e.g., `Text { "hello" }`) via the
/// `Into<TextChild>` blanket impl.
// ---------------------------------------------------------------------------
// SpliceInto — how Elements splice into a collector
// ---------------------------------------------------------------------------
/// Trait for splicing an [`Elements`] list inline into a collector.
///
/// Used by the `element!` macro's `#(expr)` syntax. Only implemented
/// for `Elements` → `Elements` — using `#(expr)` inside a data
/// collector (e.g., inside a `Line { }` block) produces a compile error.
// ---------------------------------------------------------------------------
// ChildCollector — how a component collects and finalizes children
// ---------------------------------------------------------------------------
/// Declares how a component collects children in the `element!` macro.
///
/// Implement this trait to allow your component to accept children in
/// `element!` braces. The `Collector` type determines which child types
/// are valid (via [`AddTo`]).
///
/// # Two patterns
///
/// - **Slot children** (layout containers like [`VStack`](crate::VStack)):
/// Use `Elements` as `Collector` and [`ComponentWithSlot`] as `Output`.
/// The [`impl_slot_children!`](crate::impl_slot_children) macro does this
/// automatically.
///
/// - **Data children** (like [`Text`](crate::Text)):
/// Use a custom collector type. For `#[component]` functions, the macro
/// generates a wrapper that holds the collected data.
///
/// Components without `ChildCollector` produce a compile error when used
/// with children in `element!`.
// ---------------------------------------------------------------------------
// ComponentWithSlot — wrapper for component + slot children
// ---------------------------------------------------------------------------
/// Wrapper pairing a component with its slot children.
///
/// Produced by [`ChildCollector::finish`] for layout containers.
/// The `element!` macro creates this automatically when you write
/// `Component { children... }` for a component that uses
/// [`impl_slot_children!`](crate::impl_slot_children).
// ---------------------------------------------------------------------------
// DataChildren<T> — generic collector for typed data children via Into<T>
// ---------------------------------------------------------------------------
/// Generic collector for components that accept typed data children.
///
/// `DataChildren<T>` collects children via `Into<T>` conversions, where `T`
/// is a child enum defined by the component. This replaces per-component
/// collector types with a single generic pattern.
///
/// # Example
///
/// ```ignore
/// // Component defines what children it accepts
/// enum TextChild {
/// Span(Span),
/// }
///
/// impl From<Span> for TextChild {
/// fn from(s: Span) -> Self { TextChild::Span(s) }
/// }
///
/// // #[component] generates the ChildCollector automatically:
/// // #[component(props = MyText, children = DataChildren<TextChild>)]
/// // fn my_text(props: &MyText, children: &DataChildren<TextChild>) -> Elements { ... }
/// ```
;
/// Any type that converts `Into<T>` can be added to a `DataChildren<T>` collector.
// ---------------------------------------------------------------------------
// DataHandle — no-op handle for data child additions
// ---------------------------------------------------------------------------
/// No-op handle returned when adding data children (e.g., [`Span`](crate::Span))
/// to a custom collector.
///
/// Provides `.key()` and `.width()` methods that silently do nothing,
/// so the `element!` macro's chaining syntax compiles in all contexts.
/// Keys and width constraints are only meaningful on [`Elements`] entries.
;