pub trait Component: 'static {
type State: 'static;
// Required methods
fn init(&self) -> Self::State;
fn build(&self, state: &mut Self::State) -> impl View<Self::State>;
}Expand description
A piece of UI with retained local state (Flutter’s StatefulWidget analog).
Seeds State once with Component::init and produces the subtree with
Component::build over &mut State. The subtree is any impl View over
the component’s own State; ComponentWidget erases it into an
AnyView (idempotent, so an any(..) body is not boxed twice).
Required Associated Types§
Required Methods§
Sourcefn init(&self) -> Self::State
fn init(&self) -> Self::State
Create the initial local state. Runs once, when the ComponentWidget is
first built, under the component’s Owner.
A root component has no enclosing widget, so the shell runs its
init/build under the process-lifetime root Owner: its context is
visible to the whole tree and its cleanups run at process exit.
Sourcefn build(&self, state: &mut Self::State) -> impl View<Self::State>
fn build(&self, state: &mut Self::State) -> impl View<Self::State>
Produce the subtree from the current local state.
Re-run on every rebuild and diffed against the previous view. The opaque
return type captures the &self and &mut State borrows, so a caller that
hands it out of a closure erases it first with AnyView::new(root.build(state)).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".