Skip to main content

MvuRuntime

Struct MvuRuntime 

Source
pub struct MvuRuntime<Event, Model, Props, Logic, Render, Spawn>
where Event: EventTrait, Model: Clone, Logic: MvuLogic<Event, Model, Props>, Render: Renderer<Props>, Spawn: Spawner,
{ /* private fields */ }
Expand description

The MVU runtime that orchestrates the event loop.

This is the core of the framework. It:

  1. Initializes the Model and initial Effects via MvuLogic::init
  2. Processes events through MvuLogic::update
  3. Reduces the Model to Props via MvuLogic::view
  4. Delivers Props to the Renderer for rendering

The runtime creates a single Emitter that can send events from any thread. Events are queued via a lock-free MPMC channel and processed on the thread where MvuRuntime::run was called.

For testing with manual control, use TestMvuRuntime with TestRenderer (both available with the testing feature).

See the crate-level documentation for a complete example.

§Type Parameters

  • Event - The event type for your application
  • Model - The model/state type for your application
  • Props - The props type produced by the view function
  • Logic - The logic implementation type (implements MvuLogic)
  • Render - The renderer implementation type (implements Renderer)
  • Spawn - The spawner implementation type (implements Spawner)

Implementations§

Source§

impl<Event, Model, Props, Logic, Render, Spawn> MvuRuntime<Event, Model, Props, Logic, Render, Spawn>
where Event: EventTrait, Model: Clone + 'static, Props: 'static, Logic: MvuLogic<Event, Model, Props>, Render: Renderer<Props>, Spawn: Spawner,

Source

pub fn builder( init_model: Model, logic: Logic, renderer: Render, spawner: Spawn, ) -> MvuRuntimeBuilder<Event, Model, Props, Logic, Render, Spawn>

Create a builder for configuring the runtime.

Use this when you need to customize runtime parameters like event buffer capacity.

§Arguments
  • init_model - The initial state
  • logic - Application logic implementing MvuLogic
  • renderer - Platform rendering implementation for rendering Props
  • spawner - Spawner to execute async effects on your chosen runtime
§Example
// For memory-constrained embedded systems
let runtime = MvuRuntime::builder(Model, MyLogic, MyRenderer, |_| {})
    .capacity(8)
    .build();
Source

pub async fn run(self)

Initialize the runtime and run the event processing loop.

  • Uses the MvuLogic::init function to create and enqueue initial side effects.
  • Reduces the initial Model provided at construction to Props via MvuLogic::view.
  • Renders the initial Props.
  • Processes events from the channel in a loop.

This is an async function that runs the event loop. You can spawn it on your chosen runtime using the spawner, or await it directly.

Events can be emitted from any thread via the Emitter, but are always processed sequentially on the thread where this future is awaited/polled.

Source

pub fn spawn_effect( spawner: &Spawn, emitter: &Emitter<Event>, effect: Effect<Event>, )

Auto Trait Implementations§

§

impl<Event, Model, Props, Logic, Render, Spawn> Freeze for MvuRuntime<Event, Model, Props, Logic, Render, Spawn>
where Logic: Freeze, Render: Freeze, Model: Freeze, Spawn: Freeze,

§

impl<Event, Model, Props, Logic, Render, Spawn> RefUnwindSafe for MvuRuntime<Event, Model, Props, Logic, Render, Spawn>
where Logic: RefUnwindSafe, Render: RefUnwindSafe, Model: RefUnwindSafe, Spawn: RefUnwindSafe, Props: RefUnwindSafe,

§

impl<Event, Model, Props, Logic, Render, Spawn> Send for MvuRuntime<Event, Model, Props, Logic, Render, Spawn>
where Logic: Send, Render: Send, Model: Send, Spawn: Send, Props: Send,

§

impl<Event, Model, Props, Logic, Render, Spawn> Sync for MvuRuntime<Event, Model, Props, Logic, Render, Spawn>
where Logic: Sync, Render: Sync, Model: Sync, Spawn: Sync, Props: Sync,

§

impl<Event, Model, Props, Logic, Render, Spawn> !Unpin for MvuRuntime<Event, Model, Props, Logic, Render, Spawn>

§

impl<Event, Model, Props, Logic, Render, Spawn> UnwindSafe for MvuRuntime<Event, Model, Props, Logic, Render, Spawn>
where Logic: UnwindSafe, Render: UnwindSafe, Model: UnwindSafe, Spawn: UnwindSafe, Props: 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.