Trait relm4::component::AsyncComponent
source · 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<'async_trait>(
init: Self::Init,
root: Self::Root,
sender: AsyncComponentSender<Self>
) -> Pin<Box<dyn Future<Output = AsyncComponentParts<Self>> + 'async_trait>>
where Self: 'async_trait;
// Provided methods
fn builder() -> AsyncComponentBuilder<Self> { ... }
fn init_loading_widgets(_root: &mut Self::Root) -> Option<LoadingWidgets> { ... }
fn update<'life0, 'life1, 'async_trait>(
&'life0 mut self,
message: Self::Input,
sender: AsyncComponentSender<Self>,
root: &'life1 Self::Root
) -> Pin<Box<dyn Future<Output = ()> + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn update_cmd<'life0, 'life1, 'async_trait>(
&'life0 mut self,
message: Self::CommandOutput,
sender: AsyncComponentSender<Self>,
root: &'life1 Self::Root
) -> Pin<Box<dyn Future<Output = ()> + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn update_cmd_with_view<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
widgets: &'life1 mut Self::Widgets,
message: Self::CommandOutput,
sender: AsyncComponentSender<Self>,
root: &'life2 Self::Root
) -> Pin<Box<dyn Future<Output = ()> + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn update_view(
&self,
widgets: &mut Self::Widgets,
sender: AsyncComponentSender<Self>
) { ... }
fn update_with_view<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
widgets: &'life1 mut Self::Widgets,
message: Self::Input,
sender: AsyncComponentSender<Self>,
root: &'life2 Self::Root
) -> Pin<Box<dyn Future<Output = ()> + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
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§
sourcetype CommandOutput: Debug + Send + 'static
type CommandOutput: Debug + Send + 'static
Messages which are received from commands executing in the background.
Required Methods§
sourcefn init<'async_trait>(
init: Self::Init,
root: Self::Root,
sender: AsyncComponentSender<Self>
) -> Pin<Box<dyn Future<Output = AsyncComponentParts<Self>> + 'async_trait>>where
Self: 'async_trait,
fn init<'async_trait>( init: Self::Init, root: Self::Root, sender: AsyncComponentSender<Self> ) -> Pin<Box<dyn Future<Output = AsyncComponentParts<Self>> + 'async_trait>>where Self: 'async_trait,
Creates the initial model and view, docking it into the component.
Provided Methods§
sourcefn builder() -> AsyncComponentBuilder<Self>
fn builder() -> AsyncComponentBuilder<Self>
Create a builder for this component.
sourcefn init_loading_widgets(_root: &mut Self::Root) -> Option<LoadingWidgets>
fn init_loading_widgets(_root: &mut 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.
sourcefn update<'life0, 'life1, 'async_trait>(
&'life0 mut self,
message: Self::Input,
sender: AsyncComponentSender<Self>,
root: &'life1 Self::Root
) -> Pin<Box<dyn Future<Output = ()> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn update<'life0, 'life1, 'async_trait>( &'life0 mut self, message: Self::Input, sender: AsyncComponentSender<Self>, root: &'life1 Self::Root ) -> Pin<Box<dyn Future<Output = ()> + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Processes inputs received by the component.
sourcefn update_cmd<'life0, 'life1, 'async_trait>(
&'life0 mut self,
message: Self::CommandOutput,
sender: AsyncComponentSender<Self>,
root: &'life1 Self::Root
) -> Pin<Box<dyn Future<Output = ()> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn update_cmd<'life0, 'life1, 'async_trait>( &'life0 mut self, message: Self::CommandOutput, sender: AsyncComponentSender<Self>, root: &'life1 Self::Root ) -> Pin<Box<dyn Future<Output = ()> + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Defines how the component should respond to command updates.
sourcefn update_cmd_with_view<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
widgets: &'life1 mut Self::Widgets,
message: Self::CommandOutput,
sender: AsyncComponentSender<Self>,
root: &'life2 Self::Root
) -> Pin<Box<dyn Future<Output = ()> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn update_cmd_with_view<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, widgets: &'life1 mut Self::Widgets, message: Self::CommandOutput, sender: AsyncComponentSender<Self>, root: &'life2 Self::Root ) -> Pin<Box<dyn Future<Output = ()> + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,
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.
sourcefn update_view(
&self,
widgets: &mut Self::Widgets,
sender: AsyncComponentSender<Self>
)
fn update_view( &self, widgets: &mut Self::Widgets, sender: AsyncComponentSender<Self> )
Updates the view after the model has been updated.
sourcefn update_with_view<'life0, 'life1, 'life2, 'async_trait>(
&'life0 mut self,
widgets: &'life1 mut Self::Widgets,
message: Self::Input,
sender: AsyncComponentSender<Self>,
root: &'life2 Self::Root
) -> Pin<Box<dyn Future<Output = ()> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn update_with_view<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, widgets: &'life1 mut Self::Widgets, message: Self::Input, sender: AsyncComponentSender<Self>, root: &'life2 Self::Root ) -> Pin<Box<dyn Future<Output = ()> + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,
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.