Skip to main content

HostSchema

Trait HostSchema 

Source
pub trait HostSchema: Sized + 'static {
    type Input: ?Sized;
    type Slots: ?Sized;
    type External: ?Sized;
    type Effect;
    type SlotWrite;
    type Record;
}
Expand description

Defines the kinds of data Rustia can exchange with your application.

Implement this trait once for an application integration. It contains no runtime data and has no methods; it only names the Rust types passed between your application and its scripts.

Here, an invocation means one Rustia::invoke operation: the period in which your application lends data to guest code and collects its outputs.

A useful way to read the two host traits is:

  • HostSchema says which types the integration uses.
  • HostContext<H> supplies the actual values for one invocation.

For example, a game might define its integration like this:

struct GameAi;

impl HostSchema for GameAi {
    type Input = SensorSnapshot;
    type Slots = SavedMemory;
    type External = DebugState;
    type Effect = Action;
    type SlotWrite = MemoryChange;
    type Record = OutputRecord;
}

Rust functions exposed to scripts—called host callbacks—can request only the part of this schema they are allowed to use. For example, an input callback can read Input, while an effect callback can only stage an Effect.

§Why the types and values are separate

A Rustia<H> VM and its registered functions can live for a long time. The HostContext passed to Rustia::invoke is borrowed only while that invocation runs. Keeping them separate means a short-lived context can safely borrow data from the current frame, tick, or request; Rustia never stores those borrowed values.

Required Associated Types§

Source

type Input: ?Sized

Read-only input for the current invocation, such as a sensor snapshot or request data.

Source

type Slots: ?Sized

Read-only saved state, or “slots”, that persists between invocations.

Source

type External: ?Sized

Mutable application state for explicitly external or nondeterministic callbacks.

Profile::DeterministicSim rejects callbacks with this access before installing them.

Source

type Effect

An action or event that a script may stage with Effects::emit.

Source

type SlotWrite

A proposed change to saved slot state that a script may stage with SlotWrites::write.

Source

type Record

One output item returned to the application after a successful invocation.

HostContext::record_effect and HostContext::record_slot_write convert effects and slot writes into this common type.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl HostSchema for ()

Implementors§