@@ -102,12 +102,18 @@ macro_rules! bindgen {
102102/// // Configuration of the linker is done through a generated `add_to_linker`
103103/// // method on the bindings structure.
104104/// //
105- /// // Note that the closure provided here is a projection from `T` in
105+ /// // Note that the function provided here is a projection from `T` in
106106/// // `Store<T>` to `&mut U` where `U` implements the `HelloWorldImports`
107107/// // trait. In this case the `T`, `MyState`, is stored directly in the
108108/// // structure so no projection is necessary here.
109+ /// //
110+ /// // Note that the second type parameter of `add_to_linker` is chosen here
111+ /// // as the built-in `HasSelf` type in Wasmtime. This effectively says
112+ /// // that our function isn't actually projecting, it's returning the
113+ /// // input, so `HasSelf<_>` is a convenience to avoid writing a custom
114+ /// // `HasData` implementation.
109115/// let mut linker = Linker::new(&engine);
110- /// HelloWorld::add_to_linker(&mut linker, |state: &mut MyState | state)?;
116+ /// HelloWorld::add_to_linker::<_, HasSelf<_>> (&mut linker, |state| state)?;
111117///
112118/// // As with the core wasm API of Wasmtime instantiation occurs within a
113119/// // `Store`. The bindings structure contains an `instantiate` method which
@@ -167,7 +173,7 @@ pub mod _0_hello_world;
167173/// let component = Component::from_file(&engine, "./your-component.wasm")?;
168174///
169175/// let mut linker = Linker::new(&engine);
170- /// MyWorld::add_to_linker(&mut linker, |state: &mut MyState | state)?;
176+ /// MyWorld::add_to_linker::<_, HasSelf<_>> (&mut linker, |state| state)?;
171177///
172178/// let mut store = Store::new(
173179/// &engine,
@@ -224,7 +230,7 @@ pub mod _1_world_imports;
224230/// let component = Component::from_file(&engine, "./your-component.wasm")?;
225231///
226232/// let mut linker = Linker::new(&engine);
227- /// HelloWorld::add_to_linker(&mut linker, |state: &mut MyState | state)?;
233+ /// HelloWorld::add_to_linker::<_, HasSelf<_>> (&mut linker, |state| state)?;
228234///
229235/// let mut store = Store::new(
230236/// &engine,
@@ -384,7 +390,7 @@ pub mod _4_imported_resources;
384390///
385391/// ```rust
386392/// use wasmtime::{Result, Engine, Store};
387- /// use wasmtime::component::{bindgen, Component, Linker};
393+ /// use wasmtime::component::{bindgen, Component, Linker, HasSelf };
388394///
389395#[ doc = include_str ! ( "./_5_all_world_export_kinds.rs" ) ]
390396///
@@ -402,7 +408,7 @@ pub mod _4_imported_resources;
402408/// let component = Component::from_file(&engine, "./your-component.wasm")?;
403409///
404410/// let mut linker = Linker::new(&engine);
405- /// WithExports::add_to_linker(&mut linker, |state: &mut MyState | state)?;
411+ /// WithExports::add_to_linker::<_, HasSelf<_>> (&mut linker, |state| state)?;
406412///
407413/// let mut store = Store::new(&engine, MyState);
408414/// let bindings = WithExports::instantiate(&mut store, &component, &linker)?;
0 commit comments