178b1eb4eSTrevor Elliott /// Auto-generated bindings for a pre-instantiated version of a 278b1eb4eSTrevor Elliott /// component which implements the world `imports`. 378b1eb4eSTrevor Elliott /// 478b1eb4eSTrevor Elliott /// This structure is created through [`ImportsPre::new`] which 578b1eb4eSTrevor Elliott /// takes a [`InstancePre`](wasmtime::component::InstancePre) that 678b1eb4eSTrevor Elliott /// has been created through a [`Linker`](wasmtime::component::Linker). 778b1eb4eSTrevor Elliott /// 878b1eb4eSTrevor Elliott /// For more information see [`Imports`] as well. 9f81c0dc0SAlex Crichton pub struct ImportsPre<T: 'static> { 1078b1eb4eSTrevor Elliott instance_pre: wasmtime::component::InstancePre<T>, 1178b1eb4eSTrevor Elliott indices: ImportsIndices, 1278b1eb4eSTrevor Elliott } 13f81c0dc0SAlex Crichton impl<T: 'static> Clone for ImportsPre<T> { clone(&self) -> Self1478b1eb4eSTrevor Elliott fn clone(&self) -> Self { 1578b1eb4eSTrevor Elliott Self { 1678b1eb4eSTrevor Elliott instance_pre: self.instance_pre.clone(), 1778b1eb4eSTrevor Elliott indices: self.indices.clone(), 1878b1eb4eSTrevor Elliott } 1978b1eb4eSTrevor Elliott } 2078b1eb4eSTrevor Elliott } 21f81c0dc0SAlex Crichton impl<_T: 'static> ImportsPre<_T> { 2278b1eb4eSTrevor Elliott /// Creates a new copy of `ImportsPre` bindings which can then 2378b1eb4eSTrevor Elliott /// be used to instantiate into a particular store. 2478b1eb4eSTrevor Elliott /// 2578b1eb4eSTrevor Elliott /// This method may fail if the component behind `instance_pre` 2678b1eb4eSTrevor Elliott /// does not have the required exports. new( instance_pre: wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result<Self>2778b1eb4eSTrevor Elliott pub fn new( 2878b1eb4eSTrevor Elliott instance_pre: wasmtime::component::InstancePre<_T>, 2978b1eb4eSTrevor Elliott ) -> wasmtime::Result<Self> { 30bb77f602SPat Hickey let indices = ImportsIndices::new(&instance_pre)?; 3178b1eb4eSTrevor Elliott Ok(Self { instance_pre, indices }) 3278b1eb4eSTrevor Elliott } engine(&self) -> &wasmtime::Engine3378b1eb4eSTrevor Elliott pub fn engine(&self) -> &wasmtime::Engine { 3478b1eb4eSTrevor Elliott self.instance_pre.engine() 3578b1eb4eSTrevor Elliott } instance_pre(&self) -> &wasmtime::component::InstancePre<_T>3678b1eb4eSTrevor Elliott pub fn instance_pre(&self) -> &wasmtime::component::InstancePre<_T> { 3778b1eb4eSTrevor Elliott &self.instance_pre 3878b1eb4eSTrevor Elliott } 3978b1eb4eSTrevor Elliott /// Instantiates a new instance of [`Imports`] within the 4078b1eb4eSTrevor Elliott /// `store` provided. 4178b1eb4eSTrevor Elliott /// 4278b1eb4eSTrevor Elliott /// This function will use `self` as the pre-instantiated 4378b1eb4eSTrevor Elliott /// instance to perform instantiation. Afterwards the preloaded 4478b1eb4eSTrevor Elliott /// indices in `self` are used to lookup all exports on the 4578b1eb4eSTrevor Elliott /// resulting instance. instantiate( &self, mut store: impl wasmtime::AsContextMut<Data = _T>, ) -> wasmtime::Result<Imports>461155d6dfSAlex Crichton pub fn instantiate( 471155d6dfSAlex Crichton &self, 481155d6dfSAlex Crichton mut store: impl wasmtime::AsContextMut<Data = _T>, 491155d6dfSAlex Crichton ) -> wasmtime::Result<Imports> { 501155d6dfSAlex Crichton let mut store = store.as_context_mut(); 511155d6dfSAlex Crichton let instance = self.instance_pre.instantiate(&mut store)?; 521155d6dfSAlex Crichton self.indices.load(&mut store, &instance) 531155d6dfSAlex Crichton } 541155d6dfSAlex Crichton } 551155d6dfSAlex Crichton impl<_T: Send + 'static> ImportsPre<_T> { 561155d6dfSAlex Crichton /// Same as [`Self::instantiate`], except with `async`. instantiate_async( &self, mut store: impl wasmtime::AsContextMut<Data = _T>, ) -> wasmtime::Result<Imports>5778b1eb4eSTrevor Elliott pub async fn instantiate_async( 5878b1eb4eSTrevor Elliott &self, 5978b1eb4eSTrevor Elliott mut store: impl wasmtime::AsContextMut<Data = _T>, 601155d6dfSAlex Crichton ) -> wasmtime::Result<Imports> { 6178b1eb4eSTrevor Elliott let mut store = store.as_context_mut(); 6278b1eb4eSTrevor Elliott let instance = self.instance_pre.instantiate_async(&mut store).await?; 6378b1eb4eSTrevor Elliott self.indices.load(&mut store, &instance) 6478b1eb4eSTrevor Elliott } 6578b1eb4eSTrevor Elliott } 6678b1eb4eSTrevor Elliott /// Auto-generated bindings for index of the exports of 6778b1eb4eSTrevor Elliott /// `imports`. 6878b1eb4eSTrevor Elliott /// 6978b1eb4eSTrevor Elliott /// This is an implementation detail of [`ImportsPre`] and can 7078b1eb4eSTrevor Elliott /// be constructed if needed as well. 7178b1eb4eSTrevor Elliott /// 7278b1eb4eSTrevor Elliott /// For more information see [`Imports`] as well. 7378b1eb4eSTrevor Elliott #[derive(Clone)] 7478b1eb4eSTrevor Elliott pub struct ImportsIndices {} 7578b1eb4eSTrevor Elliott /// Auto-generated bindings for an instance a component which 7678b1eb4eSTrevor Elliott /// implements the world `imports`. 7778b1eb4eSTrevor Elliott /// 7878b1eb4eSTrevor Elliott /// This structure can be created through a number of means 7978b1eb4eSTrevor Elliott /// depending on your requirements and what you have on hand: 8078b1eb4eSTrevor Elliott /// 8178b1eb4eSTrevor Elliott /// * The most convenient way is to use 821155d6dfSAlex Crichton /// [`Imports::instantiate`] which only needs a 8378b1eb4eSTrevor Elliott /// [`Store`], [`Component`], and [`Linker`]. 8478b1eb4eSTrevor Elliott /// 8578b1eb4eSTrevor Elliott /// * Alternatively you can create a [`ImportsPre`] ahead of 8678b1eb4eSTrevor Elliott /// time with a [`Component`] to front-load string lookups 8778b1eb4eSTrevor Elliott /// of exports once instead of per-instantiation. This 881155d6dfSAlex Crichton /// method then uses [`ImportsPre::instantiate`] to 8978b1eb4eSTrevor Elliott /// create a [`Imports`]. 9078b1eb4eSTrevor Elliott /// 9178b1eb4eSTrevor Elliott /// * If you've instantiated the instance yourself already 9278b1eb4eSTrevor Elliott /// then you can use [`Imports::new`]. 9378b1eb4eSTrevor Elliott /// 9478b1eb4eSTrevor Elliott /// These methods are all equivalent to one another and move 9578b1eb4eSTrevor Elliott /// around the tradeoff of what work is performed when. 9678b1eb4eSTrevor Elliott /// 9778b1eb4eSTrevor Elliott /// [`Store`]: wasmtime::Store 9878b1eb4eSTrevor Elliott /// [`Component`]: wasmtime::component::Component 9978b1eb4eSTrevor Elliott /// [`Linker`]: wasmtime::component::Linker 10078b1eb4eSTrevor Elliott pub struct Imports {} 10178b1eb4eSTrevor Elliott const _: () = { 10278b1eb4eSTrevor Elliott impl ImportsIndices { 10378b1eb4eSTrevor Elliott /// Creates a new copy of `ImportsIndices` bindings which can then 10478b1eb4eSTrevor Elliott /// be used to instantiate into a particular store. 10578b1eb4eSTrevor Elliott /// 10678b1eb4eSTrevor Elliott /// This method may fail if the component does not have the 10778b1eb4eSTrevor Elliott /// required exports. new<_T>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result<Self>108bb77f602SPat Hickey pub fn new<_T>( 109bb77f602SPat Hickey _instance_pre: &wasmtime::component::InstancePre<_T>, 11078b1eb4eSTrevor Elliott ) -> wasmtime::Result<Self> { 111bb77f602SPat Hickey let _component = _instance_pre.component(); 112bb77f602SPat Hickey let _instance_type = _instance_pre.instance_type(); 11378b1eb4eSTrevor Elliott Ok(ImportsIndices {}) 11478b1eb4eSTrevor Elliott } 11578b1eb4eSTrevor Elliott /// Uses the indices stored in `self` to load an instance 11678b1eb4eSTrevor Elliott /// of [`Imports`] from the instance provided. 11778b1eb4eSTrevor Elliott /// 11878b1eb4eSTrevor Elliott /// Note that at this time this method will additionally 11978b1eb4eSTrevor Elliott /// perform type-checks of all exports. load( &self, mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, ) -> wasmtime::Result<Imports>12078b1eb4eSTrevor Elliott pub fn load( 12178b1eb4eSTrevor Elliott &self, 12278b1eb4eSTrevor Elliott mut store: impl wasmtime::AsContextMut, 12378b1eb4eSTrevor Elliott instance: &wasmtime::component::Instance, 12478b1eb4eSTrevor Elliott ) -> wasmtime::Result<Imports> { 125bb77f602SPat Hickey let _ = &mut store; 12678b1eb4eSTrevor Elliott let _instance = instance; 12778b1eb4eSTrevor Elliott Ok(Imports {}) 12878b1eb4eSTrevor Elliott } 12978b1eb4eSTrevor Elliott } 13078b1eb4eSTrevor Elliott impl Imports { 13178b1eb4eSTrevor Elliott /// Convenience wrapper around [`ImportsPre::new`] and 1321155d6dfSAlex Crichton /// [`ImportsPre::instantiate`]. instantiate<_T>( store: impl wasmtime::AsContextMut<Data = _T>, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, ) -> wasmtime::Result<Imports>1331155d6dfSAlex Crichton pub fn instantiate<_T>( 1341155d6dfSAlex Crichton store: impl wasmtime::AsContextMut<Data = _T>, 1351155d6dfSAlex Crichton component: &wasmtime::component::Component, 1361155d6dfSAlex Crichton linker: &wasmtime::component::Linker<_T>, 1371155d6dfSAlex Crichton ) -> wasmtime::Result<Imports> { 1381155d6dfSAlex Crichton let pre = linker.instantiate_pre(component)?; 1391155d6dfSAlex Crichton ImportsPre::new(pre)?.instantiate(store) 1401155d6dfSAlex Crichton } 1411155d6dfSAlex Crichton /// Convenience wrapper around [`ImportsIndices::new`] and 1421155d6dfSAlex Crichton /// [`ImportsIndices::load`]. new( mut store: impl wasmtime::AsContextMut, instance: &wasmtime::component::Instance, ) -> wasmtime::Result<Imports>1431155d6dfSAlex Crichton pub fn new( 1441155d6dfSAlex Crichton mut store: impl wasmtime::AsContextMut, 1451155d6dfSAlex Crichton instance: &wasmtime::component::Instance, 1461155d6dfSAlex Crichton ) -> wasmtime::Result<Imports> { 1471155d6dfSAlex Crichton let indices = ImportsIndices::new(&instance.instance_pre(&store))?; 1481155d6dfSAlex Crichton indices.load(&mut store, instance) 1491155d6dfSAlex Crichton } 1501155d6dfSAlex Crichton /// Convenience wrapper around [`ImportsPre::new`] and 15178b1eb4eSTrevor Elliott /// [`ImportsPre::instantiate_async`]. instantiate_async<_T>( store: impl wasmtime::AsContextMut<Data = _T>, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, ) -> wasmtime::Result<Imports> where _T: Send,15278b1eb4eSTrevor Elliott pub async fn instantiate_async<_T>( 153bb77f602SPat Hickey store: impl wasmtime::AsContextMut<Data = _T>, 15478b1eb4eSTrevor Elliott component: &wasmtime::component::Component, 15578b1eb4eSTrevor Elliott linker: &wasmtime::component::Linker<_T>, 15678b1eb4eSTrevor Elliott ) -> wasmtime::Result<Imports> 15778b1eb4eSTrevor Elliott where 15878b1eb4eSTrevor Elliott _T: Send, 15978b1eb4eSTrevor Elliott { 16078b1eb4eSTrevor Elliott let pre = linker.instantiate_pre(component)?; 16178b1eb4eSTrevor Elliott ImportsPre::new(pre)?.instantiate_async(store).await 16278b1eb4eSTrevor Elliott } add_to_linker<T, D>( linker: &mut wasmtime::component::Linker<T>, host_getter: fn(&mut T) -> D::Data<'_>, ) -> wasmtime::Result<()> where D: a::b::interface_with_live_type::HostWithStore + a::b::interface_with_dead_type::HostWithStore + Send, for<'a> D::Data< 'a, >: a::b::interface_with_live_type::Host + a::b::interface_with_dead_type::Host + Send, T: 'static + Send,163f6775a33SAlex Crichton pub fn add_to_linker<T, D>( 16478b1eb4eSTrevor Elliott linker: &mut wasmtime::component::Linker<T>, 1657c790607SAlex Crichton host_getter: fn(&mut T) -> D::Data<'_>, 16678b1eb4eSTrevor Elliott ) -> wasmtime::Result<()> 16778b1eb4eSTrevor Elliott where 1681155d6dfSAlex Crichton D: a::b::interface_with_live_type::HostWithStore 1691155d6dfSAlex Crichton + a::b::interface_with_dead_type::HostWithStore + Send, 170f6775a33SAlex Crichton for<'a> D::Data< 171f6775a33SAlex Crichton 'a, 172f6775a33SAlex Crichton >: a::b::interface_with_live_type::Host 17378b1eb4eSTrevor Elliott + a::b::interface_with_dead_type::Host + Send, 1747c790607SAlex Crichton T: 'static + Send, 17578b1eb4eSTrevor Elliott { 1767c790607SAlex Crichton a::b::interface_with_live_type::add_to_linker::<T, D>(linker, host_getter)?; 1777c790607SAlex Crichton a::b::interface_with_dead_type::add_to_linker::<T, D>(linker, host_getter)?; 17878b1eb4eSTrevor Elliott Ok(()) 17978b1eb4eSTrevor Elliott } 18078b1eb4eSTrevor Elliott } 18178b1eb4eSTrevor Elliott }; 18278b1eb4eSTrevor Elliott pub mod a { 18378b1eb4eSTrevor Elliott pub mod b { 18478b1eb4eSTrevor Elliott #[allow(clippy::all)] 18578b1eb4eSTrevor Elliott pub mod interface_with_live_type { 18678b1eb4eSTrevor Elliott #[allow(unused_imports)] 187*96e19700SNick Fitzgerald use wasmtime::component::__internal::Box; 18878b1eb4eSTrevor Elliott #[derive(wasmtime::component::ComponentType)] 18978b1eb4eSTrevor Elliott #[derive(wasmtime::component::Lift)] 19078b1eb4eSTrevor Elliott #[derive(wasmtime::component::Lower)] 19178b1eb4eSTrevor Elliott #[component(record)] 19278b1eb4eSTrevor Elliott #[derive(Clone, Copy)] 19378b1eb4eSTrevor Elliott pub struct LiveType { 19478b1eb4eSTrevor Elliott #[component(name = "a")] 19578b1eb4eSTrevor Elliott pub a: u32, 19678b1eb4eSTrevor Elliott } 19778b1eb4eSTrevor Elliott impl core::fmt::Debug for LiveType { fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result19878b1eb4eSTrevor Elliott fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 19978b1eb4eSTrevor Elliott f.debug_struct("LiveType").field("a", &self.a).finish() 20078b1eb4eSTrevor Elliott } 20178b1eb4eSTrevor Elliott } 20278b1eb4eSTrevor Elliott const _: () = { 20378b1eb4eSTrevor Elliott assert!(4 == < LiveType as wasmtime::component::ComponentType >::SIZE32); 20478b1eb4eSTrevor Elliott assert!( 20578b1eb4eSTrevor Elliott 4 == < LiveType as wasmtime::component::ComponentType >::ALIGN32 20678b1eb4eSTrevor Elliott ); 20778b1eb4eSTrevor Elliott }; 2081155d6dfSAlex Crichton pub trait HostWithStore: wasmtime::component::HasData + Send {} 2091155d6dfSAlex Crichton impl<_T: ?Sized> HostWithStore for _T 2101155d6dfSAlex Crichton where 2111155d6dfSAlex Crichton _T: wasmtime::component::HasData + Send, 2121155d6dfSAlex Crichton {} 21378b1eb4eSTrevor Elliott pub trait Host: Send { f(&mut self) -> impl ::core::future::Future<Output = LiveType> + Send2141155d6dfSAlex Crichton fn f(&mut self) -> impl ::core::future::Future<Output = LiveType> + Send; 21578b1eb4eSTrevor Elliott } 2167c790607SAlex Crichton impl<_T: Host + ?Sized + Send> Host for &mut _T { f( &mut self, ) -> impl ::core::future::Future<Output = LiveType> + Send2171155d6dfSAlex Crichton fn f( 2181155d6dfSAlex Crichton &mut self, 2191155d6dfSAlex Crichton ) -> impl ::core::future::Future<Output = LiveType> + Send { 2201155d6dfSAlex Crichton async move { Host::f(*self).await } 2217c790607SAlex Crichton } 2227c790607SAlex Crichton } add_to_linker<T, D>( linker: &mut wasmtime::component::Linker<T>, host_getter: fn(&mut T) -> D::Data<'_>, ) -> wasmtime::Result<()> where D: HostWithStore, for<'a> D::Data<'a>: Host, T: 'static + Send,223f6775a33SAlex Crichton pub fn add_to_linker<T, D>( 22478b1eb4eSTrevor Elliott linker: &mut wasmtime::component::Linker<T>, 225f6775a33SAlex Crichton host_getter: fn(&mut T) -> D::Data<'_>, 22678b1eb4eSTrevor Elliott ) -> wasmtime::Result<()> 22778b1eb4eSTrevor Elliott where 2281155d6dfSAlex Crichton D: HostWithStore, 2297c790607SAlex Crichton for<'a> D::Data<'a>: Host, 2307c790607SAlex Crichton T: 'static + Send, 23178b1eb4eSTrevor Elliott { 23278b1eb4eSTrevor Elliott let mut inst = linker.instance("a:b/interface-with-live-type")?; 23378b1eb4eSTrevor Elliott inst.func_wrap_async( 23478b1eb4eSTrevor Elliott "f", 23578b1eb4eSTrevor Elliott move |mut caller: wasmtime::StoreContextMut<'_, T>, (): ()| { 23678b1eb4eSTrevor Elliott use tracing::Instrument; 23778b1eb4eSTrevor Elliott let span = tracing::span!( 23878b1eb4eSTrevor Elliott tracing::Level::TRACE, "wit-bindgen import", module = 23978b1eb4eSTrevor Elliott "interface-with-live-type", function = "f", 24078b1eb4eSTrevor Elliott ); 24178b1eb4eSTrevor Elliott wasmtime::component::__internal::Box::new( 24278b1eb4eSTrevor Elliott async move { 24378b1eb4eSTrevor Elliott tracing::event!(tracing::Level::TRACE, "call"); 24478b1eb4eSTrevor Elliott let host = &mut host_getter(caller.data_mut()); 24578b1eb4eSTrevor Elliott let r = Host::f(host).await; 24678b1eb4eSTrevor Elliott tracing::event!( 24778b1eb4eSTrevor Elliott tracing::Level::TRACE, result = tracing::field::debug(& r), 24878b1eb4eSTrevor Elliott "return" 24978b1eb4eSTrevor Elliott ); 25078b1eb4eSTrevor Elliott Ok((r,)) 25178b1eb4eSTrevor Elliott } 25278b1eb4eSTrevor Elliott .instrument(span), 25378b1eb4eSTrevor Elliott ) 25478b1eb4eSTrevor Elliott }, 25578b1eb4eSTrevor Elliott )?; 25678b1eb4eSTrevor Elliott Ok(()) 25778b1eb4eSTrevor Elliott } 25878b1eb4eSTrevor Elliott } 25978b1eb4eSTrevor Elliott #[allow(clippy::all)] 26078b1eb4eSTrevor Elliott pub mod interface_with_dead_type { 26178b1eb4eSTrevor Elliott #[allow(unused_imports)] 262*96e19700SNick Fitzgerald use wasmtime::component::__internal::Box; 263af31e80dSPat Hickey pub type LiveType = super::super::super::a::b::interface_with_live_type::LiveType; 264af31e80dSPat Hickey const _: () = { 265af31e80dSPat Hickey assert!(4 == < LiveType as wasmtime::component::ComponentType >::SIZE32); 266af31e80dSPat Hickey assert!( 267af31e80dSPat Hickey 4 == < LiveType as wasmtime::component::ComponentType >::ALIGN32 268af31e80dSPat Hickey ); 269af31e80dSPat Hickey }; 270af31e80dSPat Hickey #[derive(wasmtime::component::ComponentType)] 271af31e80dSPat Hickey #[derive(wasmtime::component::Lift)] 272af31e80dSPat Hickey #[derive(wasmtime::component::Lower)] 273af31e80dSPat Hickey #[component(record)] 274af31e80dSPat Hickey #[derive(Clone, Copy)] 275af31e80dSPat Hickey pub struct DeadType { 276af31e80dSPat Hickey #[component(name = "a")] 277af31e80dSPat Hickey pub a: u32, 278af31e80dSPat Hickey } 279af31e80dSPat Hickey impl core::fmt::Debug for DeadType { fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result280af31e80dSPat Hickey fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 281af31e80dSPat Hickey f.debug_struct("DeadType").field("a", &self.a).finish() 282af31e80dSPat Hickey } 283af31e80dSPat Hickey } 284af31e80dSPat Hickey const _: () = { 285af31e80dSPat Hickey assert!(4 == < DeadType as wasmtime::component::ComponentType >::SIZE32); 286af31e80dSPat Hickey assert!( 287af31e80dSPat Hickey 4 == < DeadType as wasmtime::component::ComponentType >::ALIGN32 288af31e80dSPat Hickey ); 289af31e80dSPat Hickey }; 290af31e80dSPat Hickey #[derive(wasmtime::component::ComponentType)] 291af31e80dSPat Hickey #[derive(wasmtime::component::Lift)] 292af31e80dSPat Hickey #[derive(wasmtime::component::Lower)] 293af31e80dSPat Hickey #[component(variant)] 294af31e80dSPat Hickey #[derive(Clone, Copy)] 295af31e80dSPat Hickey pub enum V { 296af31e80dSPat Hickey #[component(name = "a")] 297af31e80dSPat Hickey A(LiveType), 298af31e80dSPat Hickey #[component(name = "b")] 299af31e80dSPat Hickey B(DeadType), 300af31e80dSPat Hickey } 301af31e80dSPat Hickey impl core::fmt::Debug for V { fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result302af31e80dSPat Hickey fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { 303af31e80dSPat Hickey match self { 304af31e80dSPat Hickey V::A(e) => f.debug_tuple("V::A").field(e).finish(), 305af31e80dSPat Hickey V::B(e) => f.debug_tuple("V::B").field(e).finish(), 306af31e80dSPat Hickey } 307af31e80dSPat Hickey } 308af31e80dSPat Hickey } 309af31e80dSPat Hickey const _: () = { 310af31e80dSPat Hickey assert!(8 == < V as wasmtime::component::ComponentType >::SIZE32); 311af31e80dSPat Hickey assert!(4 == < V as wasmtime::component::ComponentType >::ALIGN32); 312af31e80dSPat Hickey }; 3131155d6dfSAlex Crichton pub trait HostWithStore: wasmtime::component::HasData {} 3141155d6dfSAlex Crichton impl<_T: ?Sized> HostWithStore for _T 3151155d6dfSAlex Crichton where 3161155d6dfSAlex Crichton _T: wasmtime::component::HasData, 3171155d6dfSAlex Crichton {} 3181155d6dfSAlex Crichton pub trait Host {} 3191155d6dfSAlex Crichton impl<_T: Host + ?Sized> Host for &mut _T {} add_to_linker<T, D>( linker: &mut wasmtime::component::Linker<T>, host_getter: fn(&mut T) -> D::Data<'_>, ) -> wasmtime::Result<()> where D: HostWithStore, for<'a> D::Data<'a>: Host, T: 'static,320f6775a33SAlex Crichton pub fn add_to_linker<T, D>( 32178b1eb4eSTrevor Elliott linker: &mut wasmtime::component::Linker<T>, 322f6775a33SAlex Crichton host_getter: fn(&mut T) -> D::Data<'_>, 32378b1eb4eSTrevor Elliott ) -> wasmtime::Result<()> 32478b1eb4eSTrevor Elliott where 3251155d6dfSAlex Crichton D: HostWithStore, 3267c790607SAlex Crichton for<'a> D::Data<'a>: Host, 3271155d6dfSAlex Crichton T: 'static, 32878b1eb4eSTrevor Elliott { 32978b1eb4eSTrevor Elliott let mut inst = linker.instance("a:b/interface-with-dead-type")?; 33078b1eb4eSTrevor Elliott Ok(()) 33178b1eb4eSTrevor Elliott } 33278b1eb4eSTrevor Elliott } 33378b1eb4eSTrevor Elliott } 33478b1eb4eSTrevor Elliott } 335