Skip to main content

Sub

Enum Sub 

Source
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.

Fields

§id: &'static str

Unique identifier for this interval

§duration: Duration

Time between emissions

§msg: Msg

Message to emit

Implementations§

Source§

impl<Msg: Clone> Sub<Msg>

Source

pub fn none() -> Self

Create an empty subscription

Source

pub fn batch(subs: impl IntoIterator<Item = Sub<Msg>>) -> Self

Create a batch of subscriptions

Source

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 emissions
  • msg: 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()
    }
}
Source§

impl<Msg> Sub<Msg>

Source

pub fn is_none(&self) -> bool

Check if this is Sub::None

Source

pub fn is_interval(&self) -> bool

Check if this is Sub::Interval

Source

pub fn is_batch(&self) -> bool

Check if this is Sub::Batch

Source

pub fn len(&self) -> usize

Get the number of subscriptions (1 for single, n for batch, 0 for none)

Source

pub fn is_empty(&self) -> bool

Check if empty

Trait Implementations§

Source§

impl<Msg: Clone> Clone for Sub<Msg>

Source§

fn clone(&self) -> Sub<Msg>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Msg> Default for Sub<Msg>

Source§

fn default() -> Sub<Msg>

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,