Struct Children

Source
pub struct Children<V> { /* private fields */ }
Expand description

A special property type to allow the component to accept children.

Add a field called children of this type to your properties struct.

§Example

#[derive(Props)]
struct RowProps {
    width: i32,
    children: Children,
}

#[component]
fn Row(props: RowProps) -> View {
    // Convert the `Children` into a `View`.
    let children = props.children.call();
    view! {
        div {
            (children)
        }
    }
}

// Using `Row` somewhere else in your app:
view! {
    Row(width=10) {
        p { "This is a child node." }
    }
}

Implementations§

Source§

impl<V> Children<V>

Source

pub fn call(self) -> V

Instantiates the child view.

Source

pub fn new(f: impl FnOnce() -> V + 'static) -> Self

Create a new Children from a closure.

Trait Implementations§

Source§

impl<V> Debug for Children<V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<V: Default + 'static> Default for Children<V>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<F, V> From<F> for Children<V>
where F: FnOnce() -> V + 'static,

Source§

fn from(f: F) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<V> Freeze for Children<V>

§

impl<V> !RefUnwindSafe for Children<V>

§

impl<V> !Send for Children<V>

§

impl<V> !Sync for Children<V>

§

impl<V> Unpin for Children<V>

§

impl<V> !UnwindSafe for Children<V>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.