Skip to main content

alloc_entity_via_export

Function alloc_entity_via_export 

Source
pub async fn alloc_entity_via_export<T>(
    caller: &mut Caller<'_, T>,
    export_name: &str,
    args: &[Val],
) -> Result<Rooted<StructRef>>
where T: Send,
Expand description

Allocates an entity wasm struct ($account, $commodity_entity, etc) by re-entering the module’s exported alloc_<kind> function. The host can’t freshly construct an entity StructType via StructType::new — fields like (ref null $i8_array) reference concrete type indices that engine canonicalization compares by identity, so any abstract anyref-typed fresh declaration produces a structurally distinct (and uncastable) type. Re-entry through the guest’s own allocator (registered in CompileContext::register_entity_allocators) sidesteps the issue: each call returns a struct ref of the exact $<kind> type the subsequent ref.cast (ref $<kind>) in the consuming form accepts.

Args are passed in declaration order matching the entity’s struct field layout (see CompileContext::new_skeleton).