unsplat component::Linker::func_wrap args (#5065)

* component::Linker::func_wrap: replace IntoComponentFunc with directly accepting a closure

We find that this makes the Linker::func_wrap type signature much easier
to read. The IntoComponentFunc abstraction was adding a lot of weight to
"splat" a set of arguments from a tuple of types into individual
arguments to the closure. Additionally, making the StoreContextMut
argument optional, or the Result<return> optional, wasn't very
worthwhile.

* Fixes for the new style of closure required by component::Linker::func_wrap

* fix fuzzing generator
This commit is contained in:
Pat Hickey
2022-10-18 07:24:14 -07:00
committed by GitHub
parent 32a7593c94
commit 78ecc17d0f
10 changed files with 107 additions and 176 deletions

View File

@@ -171,12 +171,13 @@ fn test_roundtrip(engine: &Engine, src: &str, dst: &str) -> Result<()> {
let component = Component::new(engine, &component)?;
let mut store = Store::new(engine, String::new());
let mut linker = Linker::new(engine);
linker
.root()
.func_wrap("host", |store: StoreContextMut<String>, arg: String| {
linker.root().func_wrap(
"host",
|store: StoreContextMut<String>, (arg,): (String,)| {
assert_eq!(*store.data(), arg);
Ok((arg,))
})?;
},
)?;
let instance = linker.instantiate(&mut store, &component)?;
let func = instance.get_typed_func::<(String,), (String,), _>(&mut store, "echo")?;