pub trait Component:
Send
+ Sync
+ 'static {
// Required method
fn build(&self, ctx: &mut Context) -> Element;
// Provided methods
fn on_mount(&self) { ... }
fn on_unmount(&self) { ... }
fn type_name(&self) -> &'static str { ... }
fn into_element(self) -> Element
where Self: Sized { ... }
}Expand description
The core trait every ROSACE component implements.
A component is a pure function from props (&self) and Context to an
Element tree. The framework calls build every frame (Phase 1) or when
the component is marked dirty by a state change (Phase 2+).
§Example
struct Greeting { name: String }
impl Component for Greeting {
fn build(&self, ctx: &mut Context) -> Element {
Text::new(format!("Hello, {}!", self.name)).into_element()
}
}Required Methods§
Provided Methods§
Sourcefn on_mount(&self)
fn on_mount(&self)
Called once after the component first appears in the tree.
Default implementation is a no-op. Override for side effects that should run on mount (e.g., starting timers, subscriptions).
Sourcefn on_unmount(&self)
fn on_unmount(&self)
Called once after the component is removed from the tree.
Default implementation is a no-op. Override for cleanup that cannot
be expressed as a ctx.on_cleanup closure (e.g., releasing platform
resources held by self).
Sourcefn into_element(self) -> Elementwhere
Self: Sized,
fn into_element(self) -> Elementwhere
Self: Sized,
Convert this component into an Element so it can be embedded
inside another component’s build() output.
The reconciler assigns the real position-based ComponentId during
the tree walk; ComponentId(0) here is a placeholder.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".