Trait ToChildren
pub trait ToChildren<F> {
// Required method
fn to_children(f: F) -> Self;
}
Expand description
This trait can be used when constructing a component that takes children without needing
to know exactly what children type the component expects. This is used internally by the
view!
macro implementation, and can also be used explicitly when using the builder syntax.
Different component types take different types for their children
prop, some of which cannot
be directly constructed. Using ToChildren
allows the component user to pass children without
explicitly constructing the correct type.
§Examples
use leptos::context::{Provider, ProviderProps};
use leptos::control_flow::{Show, ShowProps};
#[component]
fn App() -> impl IntoView {
(
Provider(
ProviderProps::builder()
.children(ToChildren::to_children(|| {
p().child("Foo")
}))
// ...
.value("Foo")
.build(),
),
Show(
ShowProps::builder()
.children(ToChildren::to_children(|| {
p().child("Foo")
}))
// ...
.when(|| true)
.fallback(|| p().child("foo"))
.build(),
)
)
}
Required Methods§
fn to_children(f: F) -> Self
fn to_children(f: F) -> Self
Convert the provided type (generally a closure) to Self (generally a “children” type, e.g., Children). See the implementations to see exactly which input types are supported and which “children” type they are converted to.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.