pchickey opened PR #5065 from pch/unsplat_component_func_wrap
to main
:
retire the IntoComponentFunc trait, directly accept a closure in the type signature of Linker::func_wrap.
This means "unsplatting" the arguments of the closure:
- instead of being able to write
func_wrap("", || { ... })
for a function body which requires neither the StoreContextMut nor any arguments, you have to writefunc_wrap("", |_, _:()| {...})
- Instead of being able to accept a sequence of arguments, you need to take a tuple of arguments, including our awkward friend the 1-tuple, e.g.:
func_wrap("", |_, (arg,): (u32,)| {...})
,func_wrap("", |_, (arg1, arg2): (u32, u64)| {...})
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 required.
This interface does end up being a little bit awkward for human authors, but we feel this is outweighed by making the type signature of func_wrap much nicer to read, and also mitigated by the fact that most reasonable people will be using wit-bindgen to write these func_wraps on their behalf.
pchickey requested alexcrichton for a review on PR #5065.
pchickey edited PR #5065 from pch/unsplat_component_func_wrap
to main
:
retire the
IntoComponentFunc
trait, directly accept a closure in the type signature ofcomponent::Linker::func_wrap
.This means "unsplatting" the arguments of the closure:
- instead of being able to write
func_wrap("", || { ... })
for a function body which requires neither the StoreContextMut nor any arguments, you have to writefunc_wrap("", |_, _:()| {...})
- Instead of being able to accept a sequence of arguments, you need to take a tuple of arguments, including our awkward friend the 1-tuple, e.g.:
func_wrap("", |_, (arg,): (u32,)| {...})
,func_wrap("", |_, (arg1, arg2): (u32, u64)| {...})
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 required.
This interface does end up being a little bit awkward for human authors, but we feel this is outweighed by making the type signature of func_wrap much nicer to read, and also mitigated by the fact that most reasonable people will be using wit-bindgen to write these func_wraps on their behalf.
pchickey updated PR #5065 from pch/unsplat_component_func_wrap
to main
.
alexcrichton submitted PR review.
alexcrichton merged PR #5065.
Last updated: Dec 23 2024 at 12:05 UTC