pub trait HostContext<H>where
H: HostSchema,{
// Required methods
fn input(&self) -> &H::Input;
fn slots(&self) -> &H::Slots;
fn external_mut(&mut self) -> &mut H::External;
fn record_effect(&self, sequence: u32, effect: H::Effect) -> H::Record;
fn record_slot_write(&self, sequence: u32, write: H::SlotWrite) -> H::Record;
fn record_bytes(&self, record: &H::Record) -> u64;
}Expand description
Supplies the actual host data used by one Rustia invocation.
This is usually implemented for a small, short-lived struct containing references to your application’s current data:
struct CurrentTurn<'a> {
sensors: &'a SensorSnapshot,
memory: &'a SavedMemory,
debug: &'a mut DebugState,
}Pass a value like CurrentTurn to Rustia::invoke.
Rustia borrows it only until that invocation finishes and never stores it.
A later invocation may use a completely different context value, borrowing
different application data.
The accessor methods determine what registered host callbacks can see.
Effect and slot-write callbacks do not modify application state directly;
they create Record values in Rustia’s private staging area. Rustia returns
those records only if the complete invocation succeeds.
§What Rustia can roll back
Rustia can discard staged records, but it cannot undo other mutations.
Implementations should therefore make HostContext::input,
HostContext::slots, the two record_* methods, and
HostContext::record_bytes behave like read-only calculations. Mutation
performed through HostMut—or hidden behind interior mutability—is
immediate and is not part of the record transaction.
Required Methods§
Sourcefn slots(&self) -> &H::Slots
fn slots(&self) -> &H::Slots
Returns the read-only persistent state visible to slot-reading callbacks.
Sourcefn external_mut(&mut self) -> &mut H::External
fn external_mut(&mut self) -> &mut H::External
Returns mutable application state for external or nondeterministic callbacks.
Rustia calls this only for functions registered through
HostModule::external or HostModule::nondeterministic, which
deterministic profiles reject before installation. Changes made through
this method take effect immediately and cannot be rolled back by Rustia.
Sourcefn record_effect(&self, sequence: u32, effect: H::Effect) -> H::Record
fn record_effect(&self, sequence: u32, effect: H::Effect) -> H::Record
Wraps an emitted effect in the application’s common output-record type.
sequence starts at zero and increases for each effect or slot write
staged during this invocation. It can be used to preserve the exact
order in which the script produced its outputs.
Sourcefn record_slot_write(&self, sequence: u32, write: H::SlotWrite) -> H::Record
fn record_slot_write(&self, sequence: u32, write: H::SlotWrite) -> H::Record
Wraps a staged slot write in the application’s common output-record type.
Effects and slot writes share the same increasing sequence, so their
relative order is preserved.
Sourcefn record_bytes(&self, record: &H::Record) -> u64
fn record_bytes(&self, record: &H::Record) -> u64
Reports how many logical bytes this record should consume from the invocation’s output budget.
This is application-defined accounting rather than Rust’s in-memory object size. It must return the same answer for the same record when deterministic execution is required.