Skip to main content

Component

Trait Component 

Source
pub trait Component: 'static {
    // Required method
    fn render(&self, area: Rect, buffer: &mut Buffer);

    // Provided methods
    fn on_mount(&self) { ... }
    fn on_unmount(&self) { ... }
    fn component_id(&self) -> String { ... }
    fn clone_box(&self) -> Box<dyn Component>
       where Self: Clone { ... }
    fn render_with_mount(&self, area: Rect, frame: &mut Frame<'_>)
       where Self: Clone { ... }
}

Required Methods§

Source

fn render(&self, area: Rect, buffer: &mut Buffer)

Called on every render

Provided Methods§

Source

fn on_mount(&self)

Called once when the component is first mounted

Source

fn on_unmount(&self)

Called when the component is about to be unmounted

Source

fn component_id(&self) -> String

Gets a unique identifier for this component instance

Source

fn clone_box(&self) -> Box<dyn Component>
where Self: Clone,

Clone the component into a Box This method makes the trait object-safe while still allowing cloning

Source

fn render_with_mount(&self, area: Rect, frame: &mut Frame<'_>)
where Self: Clone,

Renders the component with mount/unmount lifecycle tracking

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§