pub struct Core<Ef, A>where
A: App,{ /* private fields */ }
Expand description
The Crux core. Create an instance of this type with your effect type, and your app type as type parameters
The core interface allows passing in events of type A::Event
using Core::process_event
.
It will return back an effect of type Ef
, containing an effect request, with the input needed for processing
the effect. the Effect
type can be used by shells to dispatch to the right capability implementation.
The result of the capability’s work can then be sent back to the core using Core::resolve
, passing
in the request and the corresponding capability output type.
Implementations§
source§impl<Ef, A> Core<Ef, A>
impl<Ef, A> Core<Ef, A>
sourcepub fn new() -> Self
pub fn new() -> Self
Create an instance of the Crux core to start a Crux application, e.g.
let core: Core<HelloEffect, Hello> = Core::new();
sourcepub fn process_event(&self, event: A::Event) -> Vec<Ef>
pub fn process_event(&self, event: A::Event) -> Vec<Ef>
Run the app’s update
function with a given event
, returning a vector of
effect requests.
sourcepub fn resolve<Op>(
&self,
request: &mut Request<Op>,
result: Op::Output,
) -> Vec<Ef>where
Op: Operation,
pub fn resolve<Op>(
&self,
request: &mut Request<Op>,
result: Op::Output,
) -> Vec<Ef>where
Op: Operation,
Resolve an effect request
for operation Op
with the corresponding result.
Note that the request
is borrowed mutably. When a request that is expected to
only be resolved once is passed in, it will be consumed and changed to a request
which can no longer be resolved.