Skip to main content

WasmRunner

Struct WasmRunner 

Source
pub struct WasmRunner<M: Model> { /* private fields */ }
Expand description

Step-based program runner for WASM (no threads, no blocking).

Accepts an ftui Model and drives it through explicit step / render calls controlled by the JavaScript host.

Implementations§

Source§

impl<M: Model> WasmRunner<M>

Source

pub fn new(model: M, width: u16, height: u16) -> Self

Create a new runner with the given model and initial grid size.

The model is not initialized until init is called.

Source

pub fn init(&mut self) -> StepResult

Initialize the model by calling Model::init().

Must be called exactly once before step / render. Returns the result of executing the init command.

Source

pub fn push_event(&mut self, event: Event)

Buffer a single event for processing on the next step.

Source

pub fn push_events(&mut self, events: impl IntoIterator<Item = Event>)

Buffer multiple events for processing on the next step.

Source

pub fn step(&mut self, now: Duration) -> StepResult

Process all buffered events and fire a tick if due.

now is the monotonic timestamp from the host clock (e.g. performance.now() converted to Duration).

Returns a StepResult summarizing what happened.

Source

pub fn step_event(&mut self, event: Event) -> StepResult

Process a single event immediately (without buffering).

Source

pub fn render(&mut self) -> Option<RenderedFrame<'_>>

Render the current frame if dirty.

Returns Some(RenderedFrame) with the buffer and optional diff, or None if the view is clean (no events since last render).

Source

pub fn force_render(&mut self) -> RenderedFrame<'_>

Render the current frame unconditionally.

Source

pub fn resize(&mut self, width: u16, height: u16)

Resize the grid. Marks the view dirty and invalidates the diff baseline.

Source

pub fn is_running(&self) -> bool

Whether the program is still running (no Cmd::Quit received).

Source

pub fn is_dirty(&self) -> bool

Whether the view needs rendering.

Source

pub fn is_initialized(&self) -> bool

Whether init() has been called.

Source

pub fn size(&self) -> (u16, u16)

Current grid dimensions.

Source

pub fn frame_idx(&self) -> u64

Sequential frame index (incremented on each render).

Source

pub fn tick_rate(&self) -> Option<Duration>

Current tick rate, if set by the model.

Source

pub fn pending_events(&self) -> usize

Number of buffered events awaiting processing.

Source

pub fn model(&self) -> &M

Reference to the model.

Source

pub fn model_mut(&mut self) -> &mut M

Mutable reference to the model.

Source

pub fn drain_logs(&mut self) -> Vec<String>

Drain and return accumulated log messages.

Source

pub fn logs(&self) -> &[String]

Reference to accumulated log messages.

Source

pub fn current_buffer(&self) -> &Buffer

Reference to the most recently rendered buffer.

Auto Trait Implementations§

§

impl<M> Freeze for WasmRunner<M>
where M: Freeze,

§

impl<M> RefUnwindSafe for WasmRunner<M>
where M: RefUnwindSafe,

§

impl<M> Send for WasmRunner<M>
where M: Send,

§

impl<M> Sync for WasmRunner<M>
where M: Sync,

§

impl<M> Unpin for WasmRunner<M>
where M: Unpin,

§

impl<M> UnsafeUnpin for WasmRunner<M>
where M: UnsafeUnpin,

§

impl<M> UnwindSafe for WasmRunner<M>
where M: 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more