Struct Effect

Source
pub struct Effect<Action: Send + 'static> {
    pub value: EffectValue<Action>,
}

Fields§

§value: EffectValue<Action>

Implementations§

Source§

impl<Action> Effect<Action>
where Action: Send + 'static,

Source

pub fn map<F, MappedAction>(self, map: F) -> Effect<MappedAction>
where MappedAction: Send + 'static, F: Fn(Action) -> MappedAction + Send + Sync + 'static,

Source

pub fn run<T, Fut>(job: T) -> Self
where Fut: Future<Output = ()> + Send + 'static, T: FnOnce(AnyActionSender<Action>) -> Fut + Send + 'static,

Wraps an asynchronous unit of work that can emit actions any number of times in an effect.

For example, if you had an async stream in a dependency client:

struct EventsClient<F: Fn() -> Stream<Item = Event> {
  events: F,
}

Then you could attach to it in a run effect and sending each action of the stream back into the system:

match action {
    Action::StartButtonTapped => {
        Effect::run(async move |send| {
            let events_client = EventsClient::new().events();
            while let Some(event) = events_client.next().await {
                send.send(Action::Event(event));
            }
        })
    }
}
Source

pub fn none() -> Self

An effect that does nothing and completes immediately. Useful for situations where you must return an effect, but you don’t need to do anything.

Source

pub fn quit() -> Self

Effect that stops the reducer engine and drops observation stream, usually to gracefully exit the application.

Source

pub fn send(action: Action) -> Self

Initializes an effect that immediately emits the action passed in.

Auto Trait Implementations§

§

impl<Action> Freeze for Effect<Action>
where Action: Freeze,

§

impl<Action> !RefUnwindSafe for Effect<Action>

§

impl<Action> Send for Effect<Action>

§

impl<Action> !Sync for Effect<Action>

§

impl<Action> Unpin for Effect<Action>
where Action: Unpin,

§

impl<Action> !UnwindSafe for Effect<Action>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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