Skip to main content

Module context

Module context 

Source
Expand description

Some functions in the site component wasm ABI pass context to the Afia host.

The Afia host will then pass the context back when it calls the site component’s exported functions.

// TODO: This `afia-component` crate will eventually abstract over these `extern`
//  functions. When that happens we'll want to update this example to use the abstraction.
//  Users of this crate won't be working directly with the low-level C ABI, they'll be using
//  higher level abstractions that this crate exposes.

use afia_component::ComponentImports;

#[export_name = "__afia__$create_instance"]
pub extern "C" fn __afia_create_instance() -> isize {
    123
}

#[export_name = "__afia__$output$123$create_element"]
pub extern "C" fn create_element(context: isize, _inputs_ptr: isize, _inputs_len: usize) -> i64 {
    assert_eq!(context, 123);

    let div = ComponentImports::new_dynamically_linked().create_element("div").unwrap();
    div.temporary_way_to_get_i64()
}

This module contains types that are useful when passing and receiving context from the Afia host.

Structs§

ContextPtr
Provides a safe abstraction over context that is a mutable pointer.
OpaqueContextPtr
Wraps a context pointer such that it can be passed to the Afia host, but it cannot be accessed by the site component.

Traits§

Context
Some afia-component functions have a context parameter.