Struct iced_futures::subscription::Subscription
source · pub struct Subscription<Hasher, Event, Output> { /* private fields */ }
Expand description
A request to listen to external events.
Besides performing async actions on demand with Command
, most
applications also need to listen to external events passively.
A Subscription
is normally provided to some runtime, like a Command
,
and it will generate events as long as the user keeps requesting it.
For instance, you can use a Subscription
to listen to a WebSocket
connection, keyboard presses, mouse events, time ticks, etc.
This type is normally aliased by runtimes with a specific Event
and/or
Hasher
.
Implementations§
source§impl<H, E, O> Subscription<H, E, O>where
H: Hasher,
impl<H, E, O> Subscription<H, E, O>where H: Hasher,
sourcepub fn none() -> Self
pub fn none() -> Self
Returns an empty Subscription
that will not produce any output.
sourcepub fn from_recipe(recipe: impl Recipe<H, E, Output = O> + 'static) -> Self
pub fn from_recipe(recipe: impl Recipe<H, E, Output = O> + 'static) -> Self
Creates a Subscription
from a Recipe
describing it.
sourcepub fn batch(
subscriptions: impl IntoIterator<Item = Subscription<H, E, O>>
) -> Self
pub fn batch( subscriptions: impl IntoIterator<Item = Subscription<H, E, O>> ) -> Self
Batches all the provided subscriptions and returns the resulting
Subscription
.
sourcepub fn recipes(self) -> Vec<Box<dyn Recipe<H, E, Output = O>>>
pub fn recipes(self) -> Vec<Box<dyn Recipe<H, E, Output = O>>>
Returns the different recipes of the Subscription
.
sourcepub fn with<T>(self, value: T) -> Subscription<H, E, (T, O)>where
H: 'static,
E: 'static,
O: 'static,
T: Hash + Clone + Send + Sync + 'static,
pub fn with<T>(self, value: T) -> Subscription<H, E, (T, O)>where H: 'static, E: 'static, O: 'static, T: Hash + Clone + Send + Sync + 'static,
Adds a value to the Subscription
context.
The value will be part of the identity of a Subscription
.
sourcepub fn map<A>(self, f: fn(_: O) -> A) -> Subscription<H, E, A>where
H: 'static,
E: 'static,
O: 'static,
A: 'static,
pub fn map<A>(self, f: fn(_: O) -> A) -> Subscription<H, E, A>where H: 'static, E: 'static, O: 'static, A: 'static,
Transforms the Subscription
output with the given function.