relm4/factory/async/
traits.rs1#![allow(unused_qualifications)]
3
4use crate::Sender;
7use crate::channel::AsyncFactorySender;
8use crate::factory::{AsyncPosition, DynamicIndex, FactoryView};
9use crate::loading_widgets::LoadingWidgets;
10
11use std::fmt::Debug;
12
13pub trait AsyncFactoryComponent:
17 AsyncPosition<<Self::ParentWidget as FactoryView>::Position> + Sized + 'static
18{
19 type ParentWidget: FactoryView + 'static;
21
22 type CommandOutput: Debug + Send + 'static;
24
25 type Input: Debug + 'static;
27
28 type Output: Debug + 'static;
30
31 type Init;
33
34 type Root: AsRef<<Self::ParentWidget as FactoryView>::Children> + Debug + Clone;
36
37 type Widgets: 'static;
39
40 fn init_model(
42 init: Self::Init,
43 index: &DynamicIndex,
44 sender: AsyncFactorySender<Self>,
45 ) -> impl std::future::Future<Output = Self>;
46
47 fn init_root() -> Self::Root;
49
50 #[must_use]
57 fn init_loading_widgets(_root: Self::Root) -> Option<LoadingWidgets> {
58 None
59 }
60
61 fn init_widgets(
63 &mut self,
64 index: &DynamicIndex,
65 root: Self::Root,
66 returned_widget: &<Self::ParentWidget as FactoryView>::ReturnedWidget,
67 sender: AsyncFactorySender<Self>,
68 ) -> Self::Widgets;
69
70 #[allow(unused)]
72 fn update(
73 &mut self,
74 message: Self::Input,
75 sender: AsyncFactorySender<Self>,
76 ) -> impl std::future::Future<Output = ()> {
77 async {}
78 }
79
80 #[allow(unused)]
82 fn update_cmd(
83 &mut self,
84 message: Self::CommandOutput,
85 sender: AsyncFactorySender<Self>,
86 ) -> impl std::future::Future<Output = ()> {
87 async {}
88 }
89
90 fn update_cmd_with_view(
92 &mut self,
93 widgets: &mut Self::Widgets,
94 message: Self::CommandOutput,
95 sender: AsyncFactorySender<Self>,
96 ) -> impl std::future::Future<Output = ()> {
97 async {
98 self.update_cmd(message, sender.clone()).await;
99 self.update_view(widgets, sender);
100 }
101 }
102
103 #[allow(unused)]
105 fn update_view(&self, widgets: &mut Self::Widgets, sender: AsyncFactorySender<Self>) {}
106
107 fn update_with_view(
109 &mut self,
110 widgets: &mut Self::Widgets,
111 message: Self::Input,
112 sender: AsyncFactorySender<Self>,
113 ) -> impl std::future::Future<Output = ()> {
114 async {
115 self.update(message, sender.clone()).await;
116 self.update_view(widgets, sender);
117 }
118 }
119
120 #[allow(unused)]
122 fn shutdown(&mut self, widgets: &mut Self::Widgets, output: Sender<Self::Output>) {}
123
124 fn id(&self) -> String {
129 format!("{:p}", &self)
130 }
131}