Struct crux_core::Core

source ·
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>
where Ef: Effect, A: App,

source

pub fn new() -> Self
where A::Capabilities: WithContext<A::Event, Ef>,

Create an instance of the Crux core to start a Crux application, e.g.

let core: Core<HelloEffect, Hello> = Core::new();
source

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.

source

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.

source

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

Get the current state of the app’s view model.

Trait Implementations§

source§

impl<Ef, A> Default for Core<Ef, A>
where Ef: Effect, A: App, A::Capabilities: WithContext<A::Event, Ef>,

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Ef, A> !Freeze for Core<Ef, A>

§

impl<Ef, A> RefUnwindSafe for Core<Ef, A>

§

impl<Ef, A> Send for Core<Ef, A>
where <A as App>::Capabilities: Send, A: Send, <A as App>::Model: Send, Ef: Send,

§

impl<Ef, A> Sync for Core<Ef, A>
where <A as App>::Capabilities: Sync, A: Sync, <A as App>::Model: Send + Sync, Ef: Send,

§

impl<Ef, A> Unpin for Core<Ef, A>
where <A as App>::Capabilities: Unpin, A: Unpin, <A as App>::Model: Unpin, Ef: Unpin, <A as App>::Event: Unpin,

§

impl<Ef, A> UnwindSafe for Core<Ef, A>

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.