Skip to main content

EffectRouter

Struct EffectRouter 

Source
pub struct EffectRouter<App, RouteSet>
where App: App,
{ pub routes: RouteSet, /* private fields */ }
Expand description

Wraps a Core and routes each emitted effect to a type-specific handler.

The router owns the set of routes (RouteSet) and a routing closure which decides, per effect, which handler should process it. Any follow-up effects produced while resolving a request are passed back through the same closure, so routing decisions stay consistent across an entire chain of effects.

Construct one with EffectRouter::new. The router is always held behind an Arc so that individual routes can keep a Weak reference back to it and drive the runtime forward when they resolve requests.

Fields§

§routes: RouteSet

The set of handlers effects are routed to.

Exposed so the surrounding FFI type can reach individual routes (for example to resolve a parked or serialized request by id).

Implementations§

Source§

impl<App, RouteSet> EffectRouter<App, RouteSet>
where App: App, RouteSet: Routes<App> + Send + Sync + 'static,

Source

pub fn new<F, R>(core: Core<App>, route_effects_builder: F) -> Arc<Self>
where F: FnOnce(RouteSet) -> R, R: Fn(App::Effect) + Send + Sync + 'static,

Create a new router wrapping core.

The route set is constructed first (via Routes::new) and then passed to route_effects_builder, which returns the routing closure. Splitting construction this way lets the closure capture the routes it needs to dispatch to, while the routes themselves hold a Weak reference back to the router so they can resolve requests later.

The router is returned inside an Arc because that shared ownership is what the routes’ weak references point at; see Arc::new_cyclic.

Source

pub fn update(&self, event: App::Event)

Process an event from the shell and route every resulting effect.

This is the router’s equivalent of Core::process_event: it forwards the event to the wrapped core and passes each emitted effect through the routing closure.

Source

pub fn resolve<Output>( &self, request: &mut impl Resolvable<Output>, output: Output, ) -> Result<(), ResolveError>

Resolve an effect Request with an output value.

§Errors

Returns an error if the request is not expected to be resolved by the underlying Core.

Source

pub fn view(&self) -> App::ViewModel

Return the current view model from the wrapped Core.

Trait Implementations§

Source§

impl<App, RouteSet, Op> ResolveSink<Op> for EffectRouter<App, RouteSet>
where App: App, RouteSet: Routes<App> + Send + Sync + 'static, Op: Operation,

Source§

fn resolve_request( &self, request: &mut Request<Op>, output: Op::Output, ) -> Result<(), ResolveError>

Resolve a Request with an output value and advance the runtime. Read more

Auto Trait Implementations§

§

impl<App, RouteSet> !Freeze for EffectRouter<App, RouteSet>

§

impl<App, RouteSet> !RefUnwindSafe for EffectRouter<App, RouteSet>

§

impl<App, RouteSet> Send for EffectRouter<App, RouteSet>
where RouteSet: Send, App: Send, <App as App>::Model: Send,

§

impl<App, RouteSet> Sync for EffectRouter<App, RouteSet>
where RouteSet: Sync, App: Sync, <App as App>::Model: Send + Sync,

§

impl<App, RouteSet> Unpin for EffectRouter<App, RouteSet>
where RouteSet: Unpin, App: Unpin, <App as App>::Model: Unpin,

§

impl<App, RouteSet> UnsafeUnpin for EffectRouter<App, RouteSet>
where RouteSet: UnsafeUnpin, App: UnsafeUnpin, <App as App>::Model: UnsafeUnpin,

§

impl<App, RouteSet> !UnwindSafe for EffectRouter<App, RouteSet>

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.