Struct relm4::factory::FactorySender
source · pub struct FactorySender<C: FactoryComponent> { /* private fields */ }
Expand description
Contains senders to send and receive messages from a Component
.
Implementations§
source§impl<C: FactoryComponent> FactorySender<C>
impl<C: FactoryComponent> FactorySender<C>
sourcepub fn input_sender(&self) -> &Sender<C::Input>
pub fn input_sender(&self) -> &Sender<C::Input>
Retrieve the sender for input messages.
Useful to forward inputs from another component. If you just need to send input messages,
input()
is more concise.
sourcepub fn output_sender(&self) -> &Sender<C::Output>
pub fn output_sender(&self) -> &Sender<C::Output>
Retrieve the sender for output messages.
Useful to forward outputs from another component. If you just need to send output messages,
output()
is more concise.
sourcepub fn command_sender(&self) -> &Sender<C::CommandOutput>
pub fn command_sender(&self) -> &Sender<C::CommandOutput>
Retrieve the sender for command output messages.
Useful to forward outputs from another component. If you just need to send output messages,
command()
is more concise.
sourcepub fn input(&self, message: C::Input)
pub fn input(&self, message: C::Input)
Emit an input to the component.
Examples found in repository?
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
fn init_widgets(
&mut self,
index: &DynamicIndex,
root: &Self::Root,
_returned_widget: >k::Widget,
sender: FactorySender<Self>,
) -> Self::Widgets {
relm4::view! {
#[local_ref]
root -> gtk::Box {
#[name(label)]
gtk::Label {
set_label: &self.value.to_string(),
set_width_chars: 3,
},
gtk::Button {
set_label: "+",
connect_clicked => CounterMsg::Increment,
},
gtk::Button {
set_label: "-",
connect_clicked => CounterMsg::Decrement,
},
gtk::Button {
set_label: "Up",
connect_clicked[sender, index] => move |_| {
sender.output(CounterOutput::MoveUp(index.clone()))
}
},
gtk::Button {
set_label: "Down",
connect_clicked[sender, index] => move |_| {
sender.output(CounterOutput::MoveDown(index.clone()))
}
},
gtk::Button {
set_label: "To Start",
connect_clicked[sender, index] => move |_| {
sender.output(CounterOutput::SendFront(index.clone()))
}
}
}
}
CounterWidgets { label }
}
sourcepub fn command<Cmd, Fut>(&self, cmd: Cmd)where
Cmd: FnOnce(Sender<C::CommandOutput>, ShutdownReceiver) -> Fut + Send + 'static,
Fut: Future<Output = ()> + Send,
pub fn command<Cmd, Fut>(&self, cmd: Cmd)where Cmd: FnOnce(Sender<C::CommandOutput>, ShutdownReceiver) -> Fut + Send + 'static, Fut: Future<Output = ()> + Send,
Spawns an asynchronous command.
You can bind the the command to the lifetime of the component
by using a ShutdownReceiver
.
sourcepub fn spawn_command<Cmd>(&self, cmd: Cmd)where
Cmd: FnOnce(Sender<C::CommandOutput>) + Send + 'static,
pub fn spawn_command<Cmd>(&self, cmd: Cmd)where Cmd: FnOnce(Sender<C::CommandOutput>) + Send + 'static,
Spawns a synchronous command.
This is particularly useful for CPU-intensive background jobs that need to run on a thread-pool in the background.
If you expect the component to be dropped while the command is running take care while sending messages!
sourcepub fn oneshot_command<Fut>(&self, future: Fut)where
Fut: Future<Output = C::CommandOutput> + Send + 'static,
pub fn oneshot_command<Fut>(&self, future: Fut)where Fut: Future<Output = C::CommandOutput> + Send + 'static,
Spawns a future that will be dropped as soon as the factory component is shut down.
Essentially, this is a simpler version of Self::command()
.
sourcepub fn spawn_oneshot_command<Cmd>(&self, cmd: Cmd)where
Cmd: FnOnce() -> C::CommandOutput + Send + 'static,
pub fn spawn_oneshot_command<Cmd>(&self, cmd: Cmd)where Cmd: FnOnce() -> C::CommandOutput + Send + 'static,
Spawns a synchronous command that will be dropped as soon as the factory component is shut down.
Essentially, this is a simpler version of Self::spawn_command()
.
source§impl<C: FactoryComponent> FactorySender<C>
impl<C: FactoryComponent> FactorySender<C>
sourcepub fn output(&self, message: C::Output)
pub fn output(&self, message: C::Output)
Emit an output to the component.
Examples found in repository?
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
fn init_widgets(
&mut self,
index: &DynamicIndex,
root: &Self::Root,
_returned_widget: >k::Widget,
sender: FactorySender<Self>,
) -> Self::Widgets {
relm4::view! {
#[local_ref]
root -> gtk::Box {
#[name(label)]
gtk::Label {
set_label: &self.value.to_string(),
set_width_chars: 3,
},
gtk::Button {
set_label: "+",
connect_clicked => CounterMsg::Increment,
},
gtk::Button {
set_label: "-",
connect_clicked => CounterMsg::Decrement,
},
gtk::Button {
set_label: "Up",
connect_clicked[sender, index] => move |_| {
sender.output(CounterOutput::MoveUp(index.clone()))
}
},
gtk::Button {
set_label: "Down",
connect_clicked[sender, index] => move |_| {
sender.output(CounterOutput::MoveDown(index.clone()))
}
},
gtk::Button {
set_label: "To Start",
connect_clicked[sender, index] => move |_| {
sender.output(CounterOutput::SendFront(index.clone()))
}
}
}
}
CounterWidgets { label }
}