Struct relm4::RelmMsgHandler
source · [−]pub struct RelmMsgHandler<Data, ParentModel> where
Data: MessageHandler<ParentModel> + 'static,
ParentModel: Model, { /* private fields */ }
Expand description
RelmMsgHandler
s are usually used to run expansive tasks on different threads and report back when they are finished
so that their parent components can keep handling UI events in the meantime.
For example you could use a RelmMsgHandler
for sending a HTTP request or for copying files.
Multiple RelmMsgHandler
s that have the same parent are usually bundled along with RelmComponent
s
and RelmWorker
s in a struct that implements Components
.
Implementations
sourceimpl<Data, ParentModel> RelmMsgHandler<Data, ParentModel> where
Data: MessageHandler<ParentModel> + 'static,
ParentModel: Model,
impl<Data, ParentModel> RelmMsgHandler<Data, ParentModel> where
Data: MessageHandler<ParentModel> + 'static,
ParentModel: Model,
sourcepub fn new(
parent_model: &ParentModel,
parent_sender: Sender<ParentModel::Msg>
) -> Self
pub fn new(
parent_model: &ParentModel,
parent_sender: Sender<ParentModel::Msg>
) -> Self
Create a new RelmMsgHandler
.
sourcepub fn send(&self, msg: Data::Msg)
pub fn send(&self, msg: Data::Msg)
Send a message to this message handler. This can be used by the parent to send messages to this message handler.
Examples found in repository
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
fn update(&mut self, msg: AppMsg, components: &AppComponents, _sender: Sender<AppMsg>) -> bool {
match msg {
AppMsg::Plus(v) => {
if self.minus || self.multiply {
self.plus = v;
}
}
AppMsg::Multiply(v) => {
if self.minus || self.plus {
self.multiply = v;
}
}
AppMsg::Minus(v) => {
if self.plus || self.multiply {
self.minus = v;
}
}
AppMsg::MaxValue(v) => {
self.range = v;
self.calculate_task();
}
AppMsg::Entry(v) => {
if self.correct_value == v as u32 {
self.feedback = "<big>😀 That was right!! 💓</big>".to_string();
self.pick_random_task_type();
self.calculate_task();
self.correct_calculations += 1;
} else {
self.feedback = "<big>😕 Unfortunately wrong. 😓</big>".to_string();
self.incorrect_calculations += 1;
}
}
AppMsg::EntryError => {
self.feedback = "<big>Please enter a valid number.</big>".to_string();
}
AppMsg::SetTimer(v) => {
self.timer_init_value = v;
}
AppMsg::StartTimer => {
// if timer is running a press on the button will reset button
// otherwise initialize the timer with the selected init value
components.timer_handler.send(TimerMsg::StartStopTimer);
if self.timer.is_some() {
self.timer = None;
} else {
self.pick_random_task_type();
self.calculate_task();
self.timer = Some(self.timer_init_value);
self.correct_calculations = 0;
self.incorrect_calculations = 0;
}
}
AppMsg::CountDown => {
if let Some(t) = &mut self.timer {
*t -= 1;
// check if time is up
if *t == 0 {
self.timer = None;
// stop timer
components.timer_handler.send(TimerMsg::StartStopTimer);
// display results
components
.dialog
.send(DialogMsg::Show(
self.correct_calculations,
self.incorrect_calculations,
))
.unwrap();
}
}
}
}
true
}
Trait Implementations
sourceimpl<Data: Clone, ParentModel: Clone> Clone for RelmMsgHandler<Data, ParentModel> where
Data: MessageHandler<ParentModel> + 'static,
ParentModel: Model,
impl<Data: Clone, ParentModel: Clone> Clone for RelmMsgHandler<Data, ParentModel> where
Data: MessageHandler<ParentModel> + 'static,
ParentModel: Model,
sourcefn clone(&self) -> RelmMsgHandler<Data, ParentModel>
fn clone(&self) -> RelmMsgHandler<Data, ParentModel>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl<Data, ParentModel> RefUnwindSafe for RelmMsgHandler<Data, ParentModel> where
Data: RefUnwindSafe,
ParentModel: RefUnwindSafe,
impl<Data, ParentModel> Send for RelmMsgHandler<Data, ParentModel> where
Data: Send,
ParentModel: Send,
impl<Data, ParentModel> Sync for RelmMsgHandler<Data, ParentModel> where
Data: Sync,
ParentModel: Sync,
impl<Data, ParentModel> Unpin for RelmMsgHandler<Data, ParentModel> where
Data: Unpin,
ParentModel: Unpin,
impl<Data, ParentModel> UnwindSafe for RelmMsgHandler<Data, ParentModel> where
Data: UnwindSafe,
ParentModel: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more