pub trait AsyncComponent: Sized + 'static {
    type CommandOutput: Debug + Send + 'static;
    type Input: Debug + 'static;
    type Output: Debug + 'static;
    type Init;
    type Root: Debug + Clone;
    type Widgets: 'static;

    // Required methods
    fn init_root() -> Self::Root;
    fn init(
        init: Self::Init,
        root: Self::Root,
        sender: AsyncComponentSender<Self>
    ) -> impl Future<Output = AsyncComponentParts<Self>>;

    // Provided methods
    fn builder() -> AsyncComponentBuilder<Self> { ... }
    fn init_loading_widgets(_root: Self::Root) -> Option<LoadingWidgets> { ... }
    fn update(
        &mut self,
        message: Self::Input,
        sender: AsyncComponentSender<Self>,
        root: &Self::Root
    ) -> impl Future<Output = ()> { ... }
    fn update_cmd(
        &mut self,
        message: Self::CommandOutput,
        sender: AsyncComponentSender<Self>,
        root: &Self::Root
    ) -> impl Future<Output = ()> { ... }
    fn update_cmd_with_view(
        &mut self,
        widgets: &mut Self::Widgets,
        message: Self::CommandOutput,
        sender: AsyncComponentSender<Self>,
        root: &Self::Root
    ) -> impl Future<Output = ()> { ... }
    fn update_view(
        &self,
        widgets: &mut Self::Widgets,
        sender: AsyncComponentSender<Self>
    ) { ... }
    fn update_with_view(
        &mut self,
        widgets: &mut Self::Widgets,
        message: Self::Input,
        sender: AsyncComponentSender<Self>,
        root: &Self::Root
    ) -> impl Future<Output = ()> { ... }
    fn shutdown(
        &mut self,
        widgets: &mut Self::Widgets,
        output: Sender<Self::Output>
    ) { ... }
    fn id(&self) -> String { ... }
}
Expand description

Asynchronous variant of Component.

AsyncComponent is powerful and flexible, but for many use-cases the SimpleAsyncComponent convenience trait will suffice.

Required Associated Types§

source

type CommandOutput: Debug + Send + 'static

Messages which are received from commands executing in the background.

source

type Input: Debug + 'static

The message type that the component accepts as inputs.

source

type Output: Debug + 'static

The message type that the component provides as outputs.

source

type Init

The parameter used to initialize the component.

source

type Root: Debug + Clone

The top-level widget of the component.

source

type Widgets: 'static

The type that’s used for storing widgets created for this component.

Required Methods§

source

fn init_root() -> Self::Root

Initializes the root widget

source

fn init( init: Self::Init, root: Self::Root, sender: AsyncComponentSender<Self> ) -> impl Future<Output = AsyncComponentParts<Self>>

Creates the initial model and view, docking it into the component.

Provided Methods§

source

fn builder() -> AsyncComponentBuilder<Self>

Create a builder for this component.

source

fn init_loading_widgets(_root: Self::Root) -> Option<LoadingWidgets>

Allows you to initialize the root widget with a temporary value as a placeholder until the init() future completes.

This method does nothing by default.

source

fn update( &mut self, message: Self::Input, sender: AsyncComponentSender<Self>, root: &Self::Root ) -> impl Future<Output = ()>

Processes inputs received by the component.

source

fn update_cmd( &mut self, message: Self::CommandOutput, sender: AsyncComponentSender<Self>, root: &Self::Root ) -> impl Future<Output = ()>

Defines how the component should respond to command updates.

source

fn update_cmd_with_view( &mut self, widgets: &mut Self::Widgets, message: Self::CommandOutput, sender: AsyncComponentSender<Self>, root: &Self::Root ) -> impl Future<Output = ()>

Updates the model and view upon completion of a command.

Overriding this method is helpful if you need access to the widgets while processing a command output.

The default implementation of this method calls update_cmd followed by update_view. If you override this method while using the component macro, you must remember to call update_view in your implementation. Otherwise, the view will not reflect the updated model.

source

fn update_view( &self, widgets: &mut Self::Widgets, sender: AsyncComponentSender<Self> )

Updates the view after the model has been updated.

source

fn update_with_view( &mut self, widgets: &mut Self::Widgets, message: Self::Input, sender: AsyncComponentSender<Self>, root: &Self::Root ) -> impl Future<Output = ()>

Updates the model and view when a new input is received.

Overriding this method is helpful if you need access to the widgets while processing an input.

The default implementation of this method calls update followed by update_view. If you override this method while using the component macro, you must remember to call update_view in your implementation. Otherwise, the view will not reflect the updated model.

source

fn shutdown( &mut self, widgets: &mut Self::Widgets, output: Sender<Self::Output> )

Last method called before a component is shut down.

This method is guaranteed to be called even when the entire application is shut down.

source

fn id(&self) -> String

An identifier for the component used for debug logging.

The default implementation of this method uses the address of the component, but implementations are free to provide more meaningful identifiers.

Object Safety§

This trait is not object safe.

Implementors§