ComponentStateMount

Trait ComponentStateMount 

Source
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§

Source

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 component
  • component - The component to mount (must implement ComponentState)
  • 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
Source

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 implement ComponentState)
  • 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.

Implementations on Foreign Types§

Source§

impl ComponentStateMount for Application<ComponentId, Msg, NoUserEvent>

Source§

fn mount_with_state<C>( &mut self, id: ComponentId, component: C, subs: Vec<Sub<ComponentId, NoUserEvent>>, ) -> AppResult<()>

Source§

fn remount_with_state<C>( &mut self, id: ComponentId, component: C, subs: Vec<Sub<ComponentId, NoUserEvent>>, ) -> AppResult<()>

Implementors§