pub trait ComponentStateMount {
// Required methods
fn mount_with_state<C>(
&mut self,
id: ComponentId,
component: C,
subs: Vec<Sub<ComponentId, NoUserEvent>>,
) -> AppResult<()>
where C: ComponentState + MockComponent + Component<Msg, NoUserEvent> + 'static;
fn remount_with_state<C>(
&mut self,
id: ComponentId,
component: C,
subs: Vec<Sub<ComponentId, NoUserEvent>>,
) -> AppResult<()>
where C: ComponentState + MockComponent + Component<Msg, NoUserEvent> + 'static;
}Expand description
Extension trait for mounting components with automatic state initialization.
Provides convenient methods for mounting components that implement ComponentState
to the TUI realm application. Automatically calls the component’s [mount()] method
during the mounting process to ensure proper initialization.
§Examples
use quetty::components::state::{ComponentState, ComponentStateMount};
use quetty::components::common::ComponentId;
// Mount a component with automatic state initialization
app.mount_with_state(
ComponentId::Messages,
my_component,
vec![]
)?;Required Methods§
Sourcefn mount_with_state<C>(
&mut self,
id: ComponentId,
component: C,
subs: Vec<Sub<ComponentId, NoUserEvent>>,
) -> AppResult<()>
fn mount_with_state<C>( &mut self, id: ComponentId, component: C, subs: Vec<Sub<ComponentId, NoUserEvent>>, ) -> AppResult<()>
Mounts a component with automatic state initialization.
This method combines component state initialization with TUI realm mounting.
It first calls ComponentState::mount() on the component, then mounts
it to the TUI realm with the specified subscriptions.
§Arguments
id- Unique identifier for the componentcomponent- The component to mount (must implementComponentState)subs- Event subscriptions for the component
§Returns
Ok(()) if mounting succeeds, or an AppError if it fails
§Errors
Returns an error if:
- Component state initialization fails
- TUI realm mounting fails
Sourcefn remount_with_state<C>(
&mut self,
id: ComponentId,
component: C,
subs: Vec<Sub<ComponentId, NoUserEvent>>,
) -> AppResult<()>
fn remount_with_state<C>( &mut self, id: ComponentId, component: C, subs: Vec<Sub<ComponentId, NoUserEvent>>, ) -> AppResult<()>
Remounts a component with automatic state initialization.
Similar to [mount_with_state], but replaces an existing component with
the same ID. Useful for refreshing components or switching between different
implementations of the same component type.
§Arguments
id- Unique identifier for the component (must already exist)component- The new component to mount (must implementComponentState)subs- Event subscriptions for the component
§Returns
Ok(()) if remounting succeeds, or an AppError if it fails
§Errors
Returns an error if:
- Component state initialization fails
- TUI realm remounting fails
- No component exists with the specified ID
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.