pub struct Effects<'a, S: AppState> {
pub out: Vec<EffectEnvelope>,
/* private fields */
}Expand description
Builder for emitting side-effects from within a reducer.
Effects accumulates EffectEnvelope values that the runtime collects
after the reducer returns. Each effect can carry optional on_ok and
on_err callbacks.
§Example
ⓘ
fn handle_save(
state: &mut MyState,
_action: Save,
ctx: &mut ReducerContext<MyState>,
) {
ctx.effects.http_get("https://api.example.com/save")
.on_ok(ctx.effects.bind(SaveOk, handle_save_ok as fn(&mut MyState, SaveOk)))
.on_err(ctx.effects.bind(SaveErr, handle_save_err as fn(&mut MyState, SaveErr)));
}Fields§
§out: Vec<EffectEnvelope>Accumulated effect envelopes, drained by the runtime after the reducer.
Implementations§
Source§impl<'a, S: AppState> Effects<'a, S>
impl<'a, S: AppState> Effects<'a, S>
pub fn new(next_req_id: u64, registry: &'a mut ActionRegistry<S>) -> Self
pub fn new_headless(next_req_id: u64) -> Self
pub fn bind<A: Action, H>(&mut self, action: A, handler: H) -> ActionEnvelope
pub fn add(&mut self, effect: SystemEffect) -> u64
pub fn system_effect( &mut self, effect: SystemEffect, ) -> EffectBuilder<'_, 'a, S>
pub fn http_get(&mut self, url: impl Into<String>) -> EffectBuilder<'_, 'a, S>
pub fn file_read(&mut self, path: impl Into<String>) -> EffectBuilder<'_, 'a, S>
pub fn cancel(&mut self, req_id: u64)
pub fn release_resource(&mut self, resource_id: u64)
Auto Trait Implementations§
impl<'a, S> Freeze for Effects<'a, S>
impl<'a, S> !RefUnwindSafe for Effects<'a, S>
impl<'a, S> Send for Effects<'a, S>
impl<'a, S> Sync for Effects<'a, S>
impl<'a, S> Unpin for Effects<'a, S>where
S: Unpin,
impl<'a, S> UnsafeUnpin for Effects<'a, S>
impl<'a, S> !UnwindSafe for Effects<'a, S>
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.