pub struct HostModule<C>where
C: HostSchema,{ /* private fields */ }Expand description
A group of Rust callbacks installed under one script name.
Registrations persist across decision resets. Each callback declares which parts of the host context it needs, checked against the selected profile.
The views constrain how a callback reaches the invocation context. Safe
Rust cannot stop a 'static callback from using captured globals or
interior mutability, so semantic purity remains an embedding contract.
Callback-panic containment also requires panic = "unwind"; an aborting
build terminates or traps before Rustia can translate the panic.
Implementations§
Source§impl<C> HostModule<C>where
C: HostSchema,
impl<C> HostModule<C>where
C: HostSchema,
Sourcepub fn new(namespace: impl Into<String>) -> Self
pub fn new(namespace: impl Into<String>) -> Self
Starts a typed host module installed under namespace.
The namespace and every function name must be non-empty and unique within this module; installation validates the complete module before exposing any binding to guest code.
Sourcepub fn function<F, S>(self, name: impl Into<String>, function: F) -> Selfwhere
F: IntoHostFunctionDefinition<C, S>,
pub fn function<F, S>(self, name: impl Into<String>, function: F) -> Selfwhere
F: IntoHostFunctionDefinition<C, S>,
Adds the same callback definition accepted by Rustia::create_function
and Rustia::register_function to this persistent namespace.
Sourcepub const fn fuel_policy(&self) -> RustiaHostFuelPolicy
pub const fn fuel_policy(&self) -> RustiaHostFuelPolicy
Returns the versioned policy used to charge host-call fuel.
Sourcepub fn functions(&self) -> impl Iterator<Item = RustiaHostFunctionInfo<'_>> + '_
pub fn functions(&self) -> impl Iterator<Item = RustiaHostFunctionInfo<'_>> + '_
Iterates over the module’s declared function metadata in install order.
Sourcepub fn pure<Func, Args, Return>(
self,
name: impl Into<String>,
fuel_cost: u32,
function: Func,
) -> Selfwhere
Func: IntoHostFunction<Args, Return>,
pub fn pure<Func, Args, Return>(
self,
name: impl Into<String>,
fuel_cost: u32,
function: Func,
) -> Selfwhere
Func: IntoHostFunction<Args, Return>,
Adds a context-free function with [OpCapability::Pure].
function has the ordinary shape Fn(A, B, ...) -> R; arguments and
returns use Rustia’s normal value conversions. A Result<R> return is
exposed as a fallible host call.
Sourcepub fn input<Func, Args, Return>(
self,
name: impl Into<String>,
fuel_cost: u32,
function: Func,
) -> Selfwhere
Func: IntoInputFunction<C, Args, Return>,
pub fn input<Func, Args, Return>(
self,
name: impl Into<String>,
fuel_cost: u32,
function: Func,
) -> Selfwhere
Func: IntoInputFunction<C, Args, Return>,
Adds a deterministic input reader.
The closure shape is for<'a> Fn(Input<'a, C>, A, B, ...) -> R.
Its first argument can access only HostContext::input.
Sourcepub fn slot_read<Func, Args, Return>(
self,
name: impl Into<String>,
fuel_cost: u32,
function: Func,
) -> Selfwhere
Func: IntoSlotReadFunction<C, Args, Return>,
pub fn slot_read<Func, Args, Return>(
self,
name: impl Into<String>,
fuel_cost: u32,
function: Func,
) -> Selfwhere
Func: IntoSlotReadFunction<C, Args, Return>,
Adds a deterministic persistent-slot reader.
The closure shape is for<'a> Fn(Slots<'a, C>, A, B, ...) -> R.
Its first argument can access only HostContext::slots.
Sourcepub fn effect<Func, Args, Return>(
self,
name: impl Into<String>,
fuel_cost: u32,
function: Func,
) -> Selfwhere
Func: IntoEffectFunction<C, Args, Return>,
pub fn effect<Func, Args, Return>(
self,
name: impl Into<String>,
fuel_cost: u32,
function: Func,
) -> Selfwhere
Func: IntoEffectFunction<C, Args, Return>,
Adds a deterministic effect recorder.
The closure shape is for<'a> Fn(Effects<'a, C>, A, B, ...) -> R.
Calls to Effects::emit stage ordered records in the current
invocation transaction.
Sourcepub fn slot_write<Func, Args, Return>(
self,
name: impl Into<String>,
fuel_cost: u32,
function: Func,
) -> Selfwhere
Func: IntoSlotWriteFunction<C, Args, Return>,
pub fn slot_write<Func, Args, Return>(
self,
name: impl Into<String>,
fuel_cost: u32,
function: Func,
) -> Selfwhere
Func: IntoSlotWriteFunction<C, Args, Return>,
Adds a deterministic persistent-slot write recorder.
The closure shape is
for<'a> Fn(SlotWrites<'a, C>, A, B, ...) -> R. Calls to
SlotWrites::write stage ordered records; they do not mutate slots
directly.
Sourcepub fn external<Func, Args, Return>(
self,
name: impl Into<String>,
fuel_cost: u32,
function: Func,
) -> Selfwhere
Func: IntoExternalFunction<C, Args, Return>,
pub fn external<Func, Args, Return>(
self,
name: impl Into<String>,
fuel_cost: u32,
function: Func,
) -> Selfwhere
Func: IntoExternalFunction<C, Args, Return>,
Adds a function that reads or mutates external host state.
The closure shape is for<'a> Fn(HostMut<'a, C>, A, B, ...) -> R.
Profile::DeterministicSim
rejects the entire module before installation. Mutations through
HostMut are immediate and cannot be rolled back by Rustia.
Sourcepub fn nondeterministic<Func, Args, Return>(
self,
name: impl Into<String>,
fuel_cost: u32,
function: Func,
) -> Selfwhere
Func: IntoExternalFunction<C, Args, Return>,
pub fn nondeterministic<Func, Args, Return>(
self,
name: impl Into<String>,
fuel_cost: u32,
function: Func,
) -> Selfwhere
Func: IntoExternalFunction<C, Args, Return>,
Adds a host operation explicitly classified as nondeterministic.
It has the same HostMut closure shape and rollback caveat as
external, but metadata distinguishes an operation
whose effect itself is nondeterministic. Deterministic profiles reject
it before installation.