Trait spin_core::HostComponent
source · 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§
Required Methods§
sourcefn add_to_linker<T: Send>(
linker: &mut Linker<T>,
get: impl Fn(&mut Data<T>) -> &mut Self::Data + Send + Sync + Copy + 'static
) -> Result<()>
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
].
sourcefn build_data(&self) -> Self::Data
fn build_data(&self) -> Self::Data
Builds new host component runtime data for HostComponentsData
.
Object Safety§
This trait is not object safe.