pub enum Sub<Msg> {
None,
Batch(Vec<Sub<Msg>>),
Interval {
id: &'static str,
duration: Duration,
msg: Msg,
},
}Expand description
A subscription representing a continuous effect
Subscriptions are declared each frame based on model state.
The runtime manages starting/stopping subscriptions as they
appear or disappear from the returned Sub.
Variants§
None
No subscription
Batch(Vec<Sub<Msg>>)
Multiple subscriptions
Interval
Periodic interval timer
Emits the message at regular intervals.
The id must be unique - subscriptions with the same ID
are considered identical and won’t be restarted.
Implementations§
Source§impl<Msg: Clone> Sub<Msg>
impl<Msg: Clone> Sub<Msg>
Sourcepub fn batch(subs: impl IntoIterator<Item = Sub<Msg>>) -> Self
pub fn batch(subs: impl IntoIterator<Item = Sub<Msg>>) -> Self
Create a batch of subscriptions
Sourcepub fn interval(id: &'static str, duration: Duration, msg: Msg) -> Self
pub fn interval(id: &'static str, duration: Duration, msg: Msg) -> Self
Create a periodic interval subscription
The message will be emitted every duration after the subscription starts.
§Arguments
id: Unique identifier. Intervals with the same ID won’t restart.duration: Time between message emissionsmsg: Message to emit each interval
§Example
ⓘ
// Auto-save every 30 seconds when enabled
fn subscriptions(model: &Model) -> Sub<Msg> {
if model.auto_save_enabled {
Sub::interval("auto_save", Duration::from_secs(30), Msg::AutoSave)
} else {
Sub::none()
}
}Trait Implementations§
Auto Trait Implementations§
impl<Msg> Freeze for Sub<Msg>where
Msg: Freeze,
impl<Msg> RefUnwindSafe for Sub<Msg>where
Msg: RefUnwindSafe,
impl<Msg> Send for Sub<Msg>where
Msg: Send,
impl<Msg> Sync for Sub<Msg>where
Msg: Sync,
impl<Msg> Unpin for Sub<Msg>where
Msg: Unpin,
impl<Msg> UnsafeUnpin for Sub<Msg>where
Msg: UnsafeUnpin,
impl<Msg> UnwindSafe for Sub<Msg>where
Msg: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more