Skip to main content

HostModule

Struct HostModule 

Source
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,

Source

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.

Source

pub fn namespace(&self) -> &str

Returns the guest-visible namespace.

Source

pub fn function<F, S>(self, name: impl Into<String>, function: F) -> Self

Adds the same callback definition accepted by Rustia::create_function and Rustia::register_function to this persistent namespace.

Source

pub const fn fuel_policy(&self) -> RustiaHostFuelPolicy

Returns the versioned policy used to charge host-call fuel.

Source

pub fn functions(&self) -> impl Iterator<Item = RustiaHostFunctionInfo<'_>> + '_

Iterates over the module’s declared function metadata in install order.

Source

pub fn pure<Func, Args, Return>( self, name: impl Into<String>, fuel_cost: u32, function: Func, ) -> Self
where 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.

Source

pub fn input<Func, Args, Return>( self, name: impl Into<String>, fuel_cost: u32, function: Func, ) -> Self
where 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.

Source

pub fn slot_read<Func, Args, Return>( self, name: impl Into<String>, fuel_cost: u32, function: Func, ) -> Self
where 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.

Source

pub fn effect<Func, Args, Return>( self, name: impl Into<String>, fuel_cost: u32, function: Func, ) -> Self
where 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.

Source

pub fn slot_write<Func, Args, Return>( self, name: impl Into<String>, fuel_cost: u32, function: Func, ) -> Self
where 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.

Source

pub fn external<Func, Args, Return>( self, name: impl Into<String>, fuel_cost: u32, function: Func, ) -> Self
where 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.

Source

pub fn nondeterministic<Func, Args, Return>( self, name: impl Into<String>, fuel_cost: u32, function: Func, ) -> Self
where 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.

Auto Trait Implementations§

§

impl<C> Freeze for HostModule<C>

§

impl<C> !RefUnwindSafe for HostModule<C>

§

impl<C> Send for HostModule<C>

§

impl<C> Sync for HostModule<C>

§

impl<C> Unpin for HostModule<C>

§

impl<C> UnsafeUnpin for HostModule<C>

§

impl<C> !UnwindSafe for HostModule<C>

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.