pub trait View<State>: 'staticwhere
State: 'static,{
type Element: Widget;
// Required methods
fn build(&self, ctx: &mut BuildCtx<'_>) -> Self::Element;
fn rebuild(
&self,
prev: &Self,
element: &mut Self::Element,
ctx: &mut BuildCtx<'_>,
) -> ChangeFlags;
// Provided methods
fn teardown(&self, _element: &mut Self::Element, _ctx: &mut BuildCtx<'_>) { ... }
fn message(&self, _element: &mut Self::Element, _state: &mut State) { ... }
}Expand description
A declarative description of a piece of UI.
Each View knows how to materialise itself into a retained Widget
(View::build) and how to reconcile a previous version of itself against
the live widget (View::rebuild). State is 'static so views never
capture borrowed data — they are values, re-created every frame.
Required Associated Types§
Required Methods§
Sourcefn build(&self, ctx: &mut BuildCtx<'_>) -> Self::Element
fn build(&self, ctx: &mut BuildCtx<'_>) -> Self::Element
Materialise a fresh widget for this view.
Sourcefn rebuild(
&self,
prev: &Self,
element: &mut Self::Element,
ctx: &mut BuildCtx<'_>,
) -> ChangeFlags
fn rebuild( &self, prev: &Self, element: &mut Self::Element, ctx: &mut BuildCtx<'_>, ) -> ChangeFlags
Reconcile prev (the previous view of the same type) against the live
element, mutating it in place and reporting what changed.
Provided Methods§
Sourcefn teardown(&self, _element: &mut Self::Element, _ctx: &mut BuildCtx<'_>)
fn teardown(&self, _element: &mut Self::Element, _ctx: &mut BuildCtx<'_>)
Tear down element when this view is being removed.
A no-op for v0 leaf views; kept in the trait so the lifecycle is complete and container/removal logic (later phases) has a hook.
Sourcefn message(&self, _element: &mut Self::Element, _state: &mut State)
fn message(&self, _element: &mut Self::Element, _state: &mut State)
Deliver an event message to this view, mutating application state.
Stubbed for v0 (no event routing yet); present so the trait shape is stable as event routing is added later.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".