Struct Component

Source
pub struct Component<P, A, F = fn(&mut Context<A>, P) -> View<A>> { /* private fields */ }
Expand description

Function-backed component storing cloneable props.

Every build clones props and passes the clone by value to render. Function items and closure expressions keep their concrete Rust type, which lets reconciliation distinguish different render implementations without adding identity methods to ComponentNode.

Existing annotations such as Component<P, A> remain valid and use the default erased function-pointer type. That explicit erasure preserves the historical type-based reconciliation contract: changing the callback while keeping the same erased type does not identify a new mount. Callers that intentionally replace an erased callback should use a distinct component type or reconciliation key.

§Examples

use ailloli_ui_runtime::component::{Component, Context, IntoView, View};
fn render(_: &mut Context<()>, label: String) -> View<()> { View::empty().key(label) }
let view = Component::new(String::from("root"), render).into_view();
assert!(matches!(view.kind, ailloli_ui_runtime::component::ViewKind::Component(_)));

Implementations§

Source§

impl<P, A, F> Component<P, A, F>
where P: Clone + 'static, A: 'static, F: Fn(&mut Context<A>, P) -> View<A> + 'static,

Source

pub fn new(props: P, render: F) -> Self

Creates a function-backed component without running render.

§Examples
use ailloli_ui_runtime::component::{Component, Context, IntoView, View};
fn render(_: &mut Context<()>, _: u8) -> View<()> { View::empty() }
let view = Component::new(7, render).into_view();
assert!(view.children.is_empty());

Trait Implementations§

Source§

impl<P, A, F> ComponentNode<A> for Component<P, A, F>
where P: Clone + 'static, A: 'static, F: Fn(&mut Context<A>, P) -> View<A> + 'static,

Source§

fn build(&self, context: &mut Context<A>) -> View<A>

Builds the retained view required by this component.

Source§

impl<P, A, F> IntoView<A> for Component<P, A, F>
where P: Clone + 'static, A: 'static, F: Fn(&mut Context<A>, P) -> View<A> + 'static,

Source§

fn into_view(self) -> View<A>

Converts this value into its retained view representation.

Auto Trait Implementations§

§

impl<P, A, F> Freeze for Component<P, A, F>
where P: Freeze, F: Freeze,

§

impl<P, A, F> RefUnwindSafe for Component<P, A, F>

§

impl<P, A, F> Send for Component<P, A, F>
where P: Send, F: Send,

§

impl<P, A, F> Sync for Component<P, A, F>
where P: Sync, F: Sync,

§

impl<P, A, F> Unpin for Component<P, A, F>
where P: Unpin, F: Unpin,

§

impl<P, A, F> UnwindSafe for Component<P, A, F>
where P: UnwindSafe, F: UnwindSafe,

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, A> IntoViewKeyExt<A> for T
where T: IntoView<A>,

Source§

fn key(self, key: impl Into<String>) -> View<A>

Converts self, assigns the owned key, and returns the view. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> ErasedDestructor for T
where T: 'static,