pub struct Core<A>where
A: App,{ /* private fields */ }Expand description
The Crux core. Create an instance of this type with your App type as the type parameter
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<A> Core<A>
impl<A> Core<A>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an instance of the Crux core to start a Crux application, e.g.
If you want to construct App and App::Model yourself instead of using default, call Self::new_with
let core: Core<MyApp> = Core::new();Source§impl<A> Core<A>where
A: App,
impl<A> Core<A>where
A: App,
Sourcepub fn new_with(app: A, model: A::Model) -> Self
pub fn new_with(app: A, model: A::Model) -> Self
Create an instance of the Crux core to start a Crux application with a given App and App::Model
let app = MyApp::new();
let model = MyModel::new();
let core = Core::new_with(app, model);Sourcepub fn process_event(&self, event: A::Event) -> Vec<A::Effect>
pub fn process_event(&self, event: A::Event) -> Vec<A::Effect>
Run the app’s update function with a given event, returning a vector of
effect requests.
§Panics
Panics if the model RwLock was poisoned.
Sourcepub fn resolve<Output>(
&self,
request: &mut impl Resolvable<Output>,
result: Output,
) -> Result<Vec<A::Effect>, ResolveError>
pub fn resolve<Output>( &self, request: &mut impl Resolvable<Output>, result: Output, ) -> Result<Vec<A::Effect>, ResolveError>
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.
§Errors
Errors if the request cannot (or should not) be resolved.
Trait Implementations§
Source§impl<A> Layer for Core<A>
impl<A> Layer for Core<A>
Source§fn update<F: Fn(Vec<Self::Effect>) + Send + Sync + 'static>(
&self,
event: Self::Event,
_effect_callback: F,
) -> Vec<Self::Effect>
fn update<F: Fn(Vec<Self::Effect>) + Send + Sync + 'static>( &self, event: Self::Event, _effect_callback: F, ) -> Vec<Self::Effect>
Core::process_event this expects an
additional argument - a callback to be called with effects requested outside of the
initial call context. Read moreSource§fn resolve<Output, F: Fn(Vec<Self::Effect>) + Send + Sync + 'static>(
&self,
request: &mut impl Resolvable<Output>,
output: Output,
_effect_callback: F,
) -> Result<Vec<Self::Effect>, ResolveError>
fn resolve<Output, F: Fn(Vec<Self::Effect>) + Send + Sync + 'static>( &self, request: &mut impl Resolvable<Output>, output: Output, _effect_callback: F, ) -> Result<Vec<Self::Effect>, ResolveError>
Core::process_event this expects an
additional argument - a callback to be called with effects requested outside of the
initial call context. Read moreSource§fn process_tasks<F>(&self, _effect_callback: F) -> Vec<Self::Effect>
fn process_tasks<F>(&self, _effect_callback: F) -> Vec<Self::Effect>
Source§fn handle_effects_using<EM>(self, middleware: EM) -> HandleEffectLayer<Self, EM>
fn handle_effects_using<EM>(self, middleware: EM) -> HandleEffectLayer<Self, EM>
middleware argument
must implement the EffectMiddleware trait.