Workaround for lifetime bound not satisfied

Hello.
I'm using the wasmtime crate in a project of mine, and am writing some helper traits for converting from tuples of Rust types to WASM-compatible types. I wrote this trait, which worked until I needed to add Send as a requirement to the returned Future.

pub unsafe trait VxToWasmList : Tuple + Sized {
    type Vx<'l> : Tuple + Send;
    type Wasm   : WasmTyList + WasmParams + WasmRet + Copy + Send + 'static;
    fn to_wasm(
        vx_val   : Self::Vx<'_>,
        instance : WasmInstance,
        store    : &mut (impl WasmAsContextMut<Data = VxRunnerState> + Send + Sync
    )) -> impl Future<Output = Result<Self::Wasm, VxRunError>> + Send;
    //                                                           ^^^^ This.
}

Calling to_wasm now causes this error:

error: lifetime bound not satisfied
this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)

Until this limitation is fixed, how can I work around it?
Thanks.

The most common workaround is async-trait. Not sure if it will work for you, but try it out! [1]

Also, are you familiar with the WebAssembly Component Model? It looks like you might be reinventing some of this work. wasmtime has support if you enable the component_model feature flag.


  1. FWIW, Niko Matsakis has a good series of blog posts that detail the unresolved problems (as of the time the articles were written). Async trait send bounds, part 1: intro · baby steps | Return type notation (send bounds, part 2) · baby steps | Trait transformers (send bounds, part 3) · baby steps | Higher-ranked projections (send bound problem, part 4) · baby steps ↩︎

2 Likes

I did not know about component_model. It looks useful, but it's not quite what I'm looking for.
async-trait did solve the issue. Pin<Box<dyn Future...>> isn't great, but until the limitation is fixed, it will do.
Thank you.