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

    // Required methods
    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 [wasmtime::component::bindgen]’s generated bindings.

§Example

use spin_core::my_interface;

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

#[async_trait]
impl my_interface::Host 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§

source

type Data: Send + Sized + 'static

Host component runtime data.

Required Methods§

source

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

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

This function signature mirrors those generated by [wasmtime::component::bindgen].

source

fn build_data(&self) -> Self::Data

Builds new host component runtime data for HostComponentsData.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<HC: HostComponent> HostComponent for Arc<HC>

§

type Data = <HC as HostComponent>::Data

source§

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

source§

fn build_data(&self) -> Self::Data

Implementors§