pub struct Effect<Event>(/* private fields */);Expand description
Declarative description of events to be processed.
Effects allow you to describe asynchronous or deferred work that will
produce events. They are returned from MvuLogic::init
and MvuLogic::update alongside the new model state.
§Example
use oxide_mvu::Effect;
#[derive(Clone)]
enum Event {
LoadData,
DataLoaded(String),
}
// Trigger a follow-up event
let effect = Effect::just(Event::LoadData);
// Combine multiple effects
let effect = Effect::batch(vec![
Effect::just(Event::LoadData),
Effect::just(Event::DataLoaded("cached".to_string())),
]);
// No side effects
let effect: Effect<Event> = Effect::none();Implementations§
Source§impl<Event: 'static> Effect<Event>
impl<Event: 'static> Effect<Event>
pub fn execute(&self, emitter: &Emitter<Event>)
Sourcepub fn just(event: Event) -> Self
pub fn just(event: Event) -> Self
Create an effect just a single event.
Useful for triggering immediate follow-up events.
§Example
use oxide_mvu::Effect;
#[derive(Clone)]
enum Event { Refresh }
let effect = Effect::just(Event::Refresh);Sourcepub fn none() -> Self
pub fn none() -> Self
Create an empty effect.
Prefer this when semantically indicating “no side effects”.
§Example
use oxide_mvu::Effect;
#[derive(Clone)]
enum Event { Increment }
let effect: Effect<Event> = Effect::none();Sourcepub fn batch(effects: Vec<Effect<Event>>) -> Self
pub fn batch(effects: Vec<Effect<Event>>) -> Self
Combine multiple effects into a single effect.
All events from all effects will be queued for processing.
§Example
use oxide_mvu::Effect;
#[derive(Clone)]
enum Event { A, B, C }
let combined = Effect::batch(vec![
Effect::just(Event::A),
Effect::just(Event::B),
Effect::just(Event::C),
]);Auto Trait Implementations§
impl<Event> Freeze for Effect<Event>
impl<Event> !RefUnwindSafe for Effect<Event>
impl<Event> Send for Effect<Event>
impl<Event> !Sync for Effect<Event>
impl<Event> Unpin for Effect<Event>
impl<Event> !UnwindSafe for Effect<Event>
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