Skip to main content

Core

Struct Core 

Source
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>
where A: App + Default, A::Model: Default,

Source

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,

Source

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);
Source

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.

Source

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.

Source

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

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

§Panics

Panics if the model lock was poisoned.

Trait Implementations§

Source§

impl<A> Default for Core<A>
where A: App + Default, A::Model: Default,

Source§

fn default() -> Self

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

impl<A> Layer for Core<A>
where A: Send + Sync + 'static + App, A::Model: Send + Sync + 'static,

Source§

type Event = <A as App>::Event

Event type expected by this layer
Source§

type Effect = <A as App>::Effect

Effect type returned by this layer
Source§

type ViewModel = <A as App>::ViewModel

ViewModel returned by this layer
Source§

fn update<F: Fn(Vec<Self::Effect>) + Send + Sync + 'static>( &self, event: Self::Event, _effect_callback: F, ) -> Vec<Self::Effect>

Process event from the Shell. Compared to Core::process_event this expects an additional argument - a callback to be called with effects requested outside of the initial call context. Read more
Source§

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>

Resolve a requested effect. Compared to Core::process_event this expects an additional argument - a callback to be called with effects requested outside of the initial call context. Read more
Source§

fn view(&self) -> Self::ViewModel

Return the current state of the view model
Source§

fn process_tasks<F>(&self, _effect_callback: F) -> Vec<Self::Effect>
where F: Fn(Vec<Self::Effect>) + Sync + Send + 'static,

Process any tasks in the effect runtime of the Core, which are able to proceed. The tasks may produce effects which will be returned by the core and may be processed by lower middleware layers. Read more
Source§

fn handle_effects_using<EM>(self, middleware: EM) -> HandleEffectLayer<Self, EM>
where EM: EffectMiddleware + 'static, Self::Effect: TryInto<Request<EM::Op>, Error = Self::Effect>,

Wrap this layer with an effect handling middleware. The middleware argument must implement the EffectMiddleware trait.
Source§

fn map_effect<NewEffect>(self) -> MapEffectLayer<Self, NewEffect>
where NewEffect: From<Self::Effect> + Send + 'static,

Wrap this layer with an effect mapping middleware to change the Effect type returned. Read more
Source§

fn bridge<Format: FfiFormat>( self, effect_callback: impl Fn(Result<Vec<u8>, BridgeError<Format>>) + Send + Sync + 'static, ) -> Bridge<Self, Format>
where Self::Effect: EffectFFI, Self::Event: for<'a> Deserialize<'a>,

Auto Trait Implementations§

§

impl<A> !Freeze for Core<A>

§

impl<A> RefUnwindSafe for Core<A>
where A: RefUnwindSafe,

§

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

§

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

§

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

§

impl<A> UnsafeUnpin for Core<A>
where A: UnsafeUnpin, <A as App>::Model: UnsafeUnpin,

§

impl<A> UnwindSafe for Core<A>
where A: UnwindSafe,

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.