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

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.

Implementations on Foreign Types§

§

impl<F, C> ToChildren<F> for Box<dyn Fn() -> AnyView + Send>
where F: Fn() -> C + Send + 'static, C: RenderHtml + Send + 'static,

§

fn to_children(f: F) -> Box<dyn Fn() -> AnyView + Send>

§

impl<F, C> ToChildren<F> for Box<dyn FnMut() -> AnyView + Send>
where F: Fn() -> C + Send + 'static, C: RenderHtml + Send + 'static,

§

fn to_children(f: F) -> Box<dyn FnMut() -> AnyView + Send>

§

impl<F, C> ToChildren<F> for Box<dyn FnMut() -> Fragment + Send>
where F: FnMut() -> C + Send + 'static, C: IntoFragment,

§

fn to_children(f: F) -> Box<dyn FnMut() -> Fragment + Send>

§

impl<F, C> ToChildren<F> for Box<dyn FnOnce() -> AnyView + Send>
where F: FnOnce() -> C + Send + 'static, C: RenderHtml + Send + 'static,

§

fn to_children(f: F) -> Box<dyn FnOnce() -> AnyView + Send>

§

impl<F, C> ToChildren<F> for Box<dyn FnOnce() -> Fragment + Send>
where F: FnOnce() -> C + Send + 'static, C: IntoFragment,

§

fn to_children(f: F) -> Box<dyn FnOnce() -> Fragment + Send>

§

impl<F, C> ToChildren<F> for Arc<dyn Fn() -> AnyView + Send + Sync>
where F: Fn() -> C + Send + Sync + 'static, C: RenderHtml + Send + 'static,

§

fn to_children(f: F) -> Arc<dyn Fn() -> AnyView + Send + Sync>

§

impl<F, C> ToChildren<F> for Arc<dyn Fn() -> Fragment + Send>
where F: Fn() -> C + Send + 'static, C: IntoFragment,

§

fn to_children(f: F) -> Arc<dyn Fn() -> Fragment + Send>

§

impl<F, Children> ToChildren<F> for RouteChildren<Children>
where F: FnOnce() -> Children,

§

fn to_children(f: F) -> RouteChildren<Children>

§

impl<T> ToChildren<ChildrenOptContainer<T>> for Box<dyn Fn() -> AnyView + Send>
where T: IntoAny + Clone + Send + 'static,

§

impl<T> ToChildren<ChildrenOptContainer<T>> for Box<dyn FnMut() -> AnyView + Send>
where T: IntoAny + Clone + Send + 'static,

§

impl<T> ToChildren<ChildrenOptContainer<T>> for Box<dyn FnMut() -> Fragment + Send>
where T: IntoAny + Clone + Send + 'static,

§

impl<T> ToChildren<ChildrenOptContainer<T>> for Box<dyn FnOnce() -> AnyView + Send>
where T: IntoAny + Send + 'static,

§

impl<T> ToChildren<ChildrenOptContainer<T>> for Box<dyn FnOnce() -> Fragment + Send>
where T: IntoAny + Send + 'static,

§

impl<T> ToChildren<ChildrenOptContainer<T>> for Arc<dyn Fn() -> AnyView + Send + Sync>
where T: IntoAny + Clone + Send + Sync + 'static,

§

fn to_children( t: ChildrenOptContainer<T>, ) -> Arc<dyn Fn() -> AnyView + Send + Sync>

§

impl<T> ToChildren<ChildrenOptContainer<T>> for Arc<dyn Fn() -> Fragment + Send>
where T: IntoAny + Clone + Send + 'static,

Implementors§

§

impl<F, C> ToChildren<F> for TypedChildren<C>
where F: FnOnce() -> C + Send + 'static, C: IntoView, <C as RenderHtml>::AsyncOutput: Send,

§

impl<F, C> ToChildren<F> for TypedChildrenFn<C>
where F: Fn() -> C + Send + Sync + 'static, C: IntoView, <C as RenderHtml>::AsyncOutput: Send,

§

impl<F, C> ToChildren<F> for TypedChildrenMut<C>
where F: FnMut() -> C + Send + 'static, C: IntoView, <C as RenderHtml>::AsyncOutput: Send,

§

impl<T> ToChildren<ChildrenOptContainer<T>> for TypedChildren<T>
where T: IntoView + 'static,

§

impl<T> ToChildren<ChildrenOptContainer<T>> for TypedChildrenFn<T>
where T: IntoView + Clone + Sync + 'static,

§

impl<T> ToChildren<ChildrenOptContainer<T>> for TypedChildrenMut<T>
where T: IntoView + Clone + 'static,