pub struct Children(/* private fields */);Expand description
A component’s markup children, not yet built.
Slots is the list a call site already made; this is the recipe for making it. The difference is the
whole of what a compound component needs, and it comes from one fact about how a tree is assembled here:
a child is an argument, so it is constructed before the parent it is passed to. A Select.Item that
wanted to know which select it belongs to, what is currently chosen, or what to call when it is picked,
was asking a question about something that did not exist yet.
Handed the recipe instead, the parent builds its context first and then runs the recipe inside it, so a
child reaches the parent through use_context rather than through props threaded
down by hand. The recipe is Fn, not FnOnce, for a second reason that is not theoretical: a dropdown
rebuilds its rows every time the panel opens, so the children have to be makeable more than once.
Implementations§
Source§impl Children
impl Children
pub fn new(build: impl Fn() -> Result<Slots, LayoutError> + 'static) -> Self
Sourcepub fn build_with<T: Any + 'static>(
&self,
context: T,
) -> Result<Slots, LayoutError>
pub fn build_with<T: Any + 'static>( &self, context: T, ) -> Result<Slots, LayoutError>
Builds the children with context visible to every one of them, and to anything they build in turn.
The scope is nested, so a select inside a select’s own row shadows the outer one rather than colliding with it, and it closes when this returns — a widget built afterwards sees nothing.
Sourcepub fn build(&self) -> Result<Slots, LayoutError>
pub fn build(&self) -> Result<Slots, LayoutError>
Builds the children with no context of their own, for a component that has nothing to tell them.