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,

source

pub fn none() -> Self

Returns an empty Subscription that will not produce any output.

source

pub fn from_recipe(recipe: impl Recipe<H, E, Output = O> + 'static) -> Self

Creates a Subscription from a Recipe describing it.

source

pub fn batch(
    subscriptions: impl IntoIterator<Item = Subscription<H, E, O>>
) -> Self

Batches all the provided subscriptions and returns the resulting Subscription.

source

pub fn recipes(self) -> Vec<Box<dyn Recipe<H, E, Output = O>>>

Returns the different recipes of the Subscription.

source

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.

source

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.

Trait Implementations§

source§

impl<I, O, H> Debug for Subscription<I, O, H>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Hasher, Event, Output> !RefUnwindSafe for Subscription<Hasher, Event, Output>

§

impl<Hasher, Event, Output> !Send for Subscription<Hasher, Event, Output>

§

impl<Hasher, Event, Output> !Sync for Subscription<Hasher, Event, Output>

§

impl<Hasher, Event, Output> Unpin for Subscription<Hasher, Event, Output>

§

impl<Hasher, Event, Output> !UnwindSafe for Subscription<Hasher, Event, Output>

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.