Skip to main content

Runtime

Struct Runtime 

Source
pub struct Runtime<S, A: Action, E = NoEffect, Routing = Direct, St = Store<S, A, E>>
where St: RuntimeStore<S, A, E>,
{ /* private fields */ }
Expand description

Runtime helper for store-driven applications.

Implementations§

Source§

impl<S, A, E, Routing, St> Runtime<S, A, E, Routing, St>
where S: 'static, A: Action, St: RuntimeStore<S, A, E>,

Source

pub fn with_event_bus<Id, Ctx>( self, bus: EventBus<S, A, Id, Ctx>, keybindings: Keybindings<Ctx>, ) -> Runtime<S, A, E, EventBusRouting<S, A, Id, Ctx>, St>
where Id: ComponentId + 'static, Ctx: BindingContext + 'static, S: EventRoutingState<Id, Ctx>,

Pair this runtime with an EventBus + Keybindings so raw events are routed through the bus before actions are dispatched.

Source§

impl<S, A, E, Id, Ctx, St> Runtime<S, A, E, EventBusRouting<S, A, Id, Ctx>, St>
where S: 'static + EventRoutingState<Id, Ctx>, A: Action, Id: ComponentId + 'static, Ctx: BindingContext + 'static, St: RuntimeStore<S, A, E>,

Source

pub fn bus(&self) -> &EventBus<S, A, Id, Ctx>

Access the event bus.

Source

pub fn bus_mut(&mut self) -> &mut EventBus<S, A, Id, Ctx>

Access the event bus mutably.

Source

pub fn keybindings(&self) -> &Keybindings<Ctx>

Access the keybindings.

Source

pub fn keybindings_mut(&mut self) -> &mut Keybindings<Ctx>

Access the keybindings mutably.

Source§

impl<S, A, Id, Ctx, St> Runtime<S, A, NoEffect, EventBusRouting<S, A, Id, Ctx>, St>
where S: 'static + EventRoutingState<Id, Ctx>, A: Action, Id: ComponentId + 'static, Ctx: BindingContext + 'static, St: RuntimeStore<S, A, NoEffect>,

Source

pub async fn run<B, FRender, FQuit>( &mut self, terminal: &mut Terminal<B>, render: FRender, should_quit: FQuit, ) -> Result<()>
where B: Backend, FRender: FnMut(&mut Frame<'_>, Rect, &S, RenderContext, &mut EventContext<Id>), FQuit: FnMut(&A) -> bool,

Run the event/action loop until quit, routing raw events through the bus + keybindings.

Source

pub async fn run_with_hooks<B, FRender, FQuit, FAfter>( &mut self, terminal: &mut Terminal<B>, render: FRender, should_quit: FQuit, after_render: FAfter, ) -> Result<()>
where B: Backend, FRender: FnMut(&mut Frame<'_>, Rect, &S, RenderContext, &mut EventContext<Id>), FQuit: FnMut(&A) -> bool, FAfter: FnMut(&mut EventBus<S, A, Id, Ctx>, &S),

Run the event/action loop with a post-render hook invoked after each frame is drawn.

Source§

impl<S, A, E, Id, Ctx, St> Runtime<S, A, E, EventBusRouting<S, A, Id, Ctx>, St>
where S: 'static + EventRoutingState<Id, Ctx>, A: Action, Id: ComponentId + 'static, Ctx: BindingContext + 'static, St: RuntimeStore<S, A, E>,

Source

pub async fn run_with_effects<B, FRender, FQuit, FEffect>( &mut self, terminal: &mut Terminal<B>, render: FRender, should_quit: FQuit, handle_effect: FEffect, ) -> Result<()>
where B: Backend, FRender: FnMut(&mut Frame<'_>, Rect, &S, RenderContext, &mut EventContext<Id>), FQuit: FnMut(&A) -> bool, FEffect: FnMut(E, &mut EffectContext<'_, A>),

Run the event/action loop until quit, routing raw events through the bus + keybindings and handling emitted effects at the run boundary.

Source

pub async fn run_with_effect_hooks<B, FRender, FQuit, FEffect, FAfter>( &mut self, terminal: &mut Terminal<B>, render: FRender, should_quit: FQuit, handle_effect: FEffect, after_render: FAfter, ) -> Result<()>
where B: Backend, FRender: FnMut(&mut Frame<'_>, Rect, &S, RenderContext, &mut EventContext<Id>), FQuit: FnMut(&A) -> bool, FEffect: FnMut(E, &mut EffectContext<'_, A>), FAfter: FnMut(&mut EventBus<S, A, Id, Ctx>, &S),

Run the event/action loop with effects and a post-render hook invoked after each frame is drawn.

Source§

impl<S: 'static, A: Action, E> Runtime<S, A, E, Direct, Store<S, A, E>>

Source

pub fn new(state: S, reducer: Reducer<S, A, E>) -> Self

Create a runtime from state + reducer.

Source§

impl<S: 'static, A: Action, E, St: RuntimeStore<S, A, E>> Runtime<S, A, E, Direct, St>

Source

pub fn from_store(store: St) -> Self

Create a runtime from an existing store.

Source§

impl<S: 'static, A: Action, E, Routing, St> Runtime<S, A, E, Routing, St>
where St: RuntimeStore<S, A, E>,

Source

pub fn with_event_poller(self, config: PollerConfig) -> Self

Configure event polling behavior.

Source

pub fn with_dispatch_error_handler<F>(self, handler: F) -> Self
where F: FnMut(&DispatchError) -> DispatchErrorPolicy + 'static,

Configure handling for recoverable dispatch errors.

The handler receives each DispatchError and selects a DispatchErrorPolicy. Runtimes do not log or store errors by default; do that inside this closure when needed.

Source

pub fn subscribe_actions(&self) -> Receiver<String>

Subscribe to action name broadcasts.

Source

pub fn enqueue(&self, action: A)

Send an action into the runtime queue.

Source

pub fn action_tx(&self) -> UnboundedSender<A>

Clone the action sender.

Source

pub fn state(&self) -> &S

Access the current state.

Source§

impl<S: 'static, A: Action, St> Runtime<S, A, NoEffect, Direct, St>
where St: RuntimeStore<S, A, NoEffect>,

Source

pub async fn run<B, FRender, FEvent, FQuit, R>( &mut self, terminal: &mut Terminal<B>, render: FRender, map_event: FEvent, should_quit: FQuit, ) -> Result<()>
where B: Backend, FRender: FnMut(&mut Frame<'_>, Rect, &S, RenderContext), FEvent: FnMut(&EventKind, &S) -> R, R: Into<EventOutcome<A>>, FQuit: FnMut(&A) -> bool,

Run the event/action loop until quit.

Source§

impl<S: 'static, A: Action, E, St> Runtime<S, A, E, Direct, St>
where St: RuntimeStore<S, A, E>,

Source

pub async fn run_with_effects<B, FRender, FEvent, FQuit, FEffect, R>( &mut self, terminal: &mut Terminal<B>, render: FRender, map_event: FEvent, should_quit: FQuit, handle_effect: FEffect, ) -> Result<()>
where B: Backend, FRender: FnMut(&mut Frame<'_>, Rect, &S, RenderContext), FEvent: FnMut(&EventKind, &S) -> R, R: Into<EventOutcome<A>>, FQuit: FnMut(&A) -> bool, FEffect: FnMut(E, &mut EffectContext<'_, A>),

Run the event/action loop until quit, handling emitted effects at the run boundary.

Auto Trait Implementations§

§

impl<S, A, E, Routing, St> Freeze for Runtime<S, A, E, Routing, St>
where St: Freeze, Routing: Freeze,

§

impl<S, A, E = NoEffect, Routing = Direct, St = Store<S, A, E>> !RefUnwindSafe for Runtime<S, A, E, Routing, St>

§

impl<S, A, E = NoEffect, Routing = Direct, St = Store<S, A, E>> !Send for Runtime<S, A, E, Routing, St>

§

impl<S, A, E = NoEffect, Routing = Direct, St = Store<S, A, E>> !Sync for Runtime<S, A, E, Routing, St>

§

impl<S, A, E, Routing, St> Unpin for Runtime<S, A, E, Routing, St>
where St: Unpin, Routing: Unpin, E: Unpin, S: Unpin,

§

impl<S, A, E, Routing, St> UnsafeUnpin for Runtime<S, A, E, Routing, St>
where St: UnsafeUnpin, Routing: UnsafeUnpin,

§

impl<S, A, E = NoEffect, Routing = Direct, St = Store<S, A, E>> !UnwindSafe for Runtime<S, A, E, Routing, St>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.