I’m trying to setup multiple subscriptions that are dynamic.
In my main app subscriptions as:
let main_subscription = event::listen().map(MainMessage::IcedEvent);
let gesture_subscription = self.gesture_handler.subscription();
Subscription::batch(vec![main_subscription, gesture_subscription]) // <- gesture subscription not liked....
and helper.subscription is like so:
fn subscription(&self) -> Subscription<Instant> {
let tick = match self.timer_enabled {
true => {
time::every(Duration::from_millis(100)).map(|_| self.update()) // every function not found in iced::time?!
},
false => Subscription::none(),
};
tick
}
How can i set this up?
That way the helper can toggle on and off its own update()
im using the example from : Subscription in iced - Rust so the return type on the function of the child is different…
Also MainMessage sounds fishy. It’s “best practice” to only have one Message in each module. I would rename MainMessage as Message and just use helper::Message to refer to the helper variant.
// main.rs
pub enum Message {
IcedEvent(iced::Event),
Helper(helper::Message),
// your other variants...
}
Use .map() like I did in my comment. Values returned by children functions are generally mapped to a variant in the equivalent parent enum.
You will generally .map() your children’s view (the returning Element), update (the returning Task<Message>) and subscription (the returning Subscription) functions.