pub trait HostComponent: Send + Sync + 'static {
    type Data: Send + Sized + 'static;

    fn add_to_linker<T: Send>(
        linker: &mut Linker<T>,
        get: impl Fn(&mut Data<T>) -> &mut Self::Data + Send + Sync + Copy + 'static
    ) -> Result<()>; fn build_data(&self) -> Self::Data; }
Expand description

A trait for Spin “host components”.

A Spin host component is an interface provided to Spin components that is implemented by the host. This trait is designed to be compatible with wit-bindgen’s generated bindings.

Example

wit_bindgen_wasmtime::export!({paths: ["my-interface.wit"], async: *});

#[derive(Default)]
struct MyHostComponent {
    // ...
}

#[async_trait]
impl my_interface::MyInterface for MyHostComponent {
    // ...
}

impl HostComponent for MyHostComponent {
    type Data = Self;

    fn add_to_linker<T: Send>(
        linker: &mut Linker<T>,
        get: impl Fn(&mut spin_core::Data<T>) -> &mut Self::Data + Send + Sync + Copy + 'static,
    ) -> anyhow::Result<()> {
        my_interface::add_to_linker(linker, get)
    }

    fn build_data(&self) -> Self::Data {
        Default::default()
    }
}

Required Associated Types§

Host component runtime data.

Required Methods§

Add this component to the given Linker, using the given runtime state-getting handle.

This function signature mirrors those generated by wit-bindgen.

Builds new host component runtime data for HostComponentsData.

Implementations on Foreign Types§

Implementors§