Closed jasontheiler closed 10 months ago
The trait bound G: rquickjs::IntoJs<'static>
makes sure that a type will only be able to be converted into a Value
with a lifetime of 'static
. Since converting to a Value
with a specific lifetime requires a Ctx
object with the exact same lifetime this bound requires Ctx
to have a 'static
lifetime inside the closure. This can never be the case thus resulting in the compile error.
Instead of 'static
try using a HRTB: G: for<'a> rquickjs::IntoJs<'a>
Thank you! That just did the trick. Lifetime is a concept I still struggle with sometimes and I never had a case before where I had to use a higher-ranked trait bound, so I didn't even think of it... Guess I have some catching up to do. Thank you again.
Hi everyone,
I'm currently trying to create a
Code
enumerator, that abstracts different implementations of various methods for different programming languages (like JavaScript and Lua). Now, this is probably not an issue with the library itself, but I'm having problems with the lifetime of theCtx
when I userquickjs
inside a function that takes a generic for either a parameter or a return value.I always run into the error that borrowed data escapes outside of the closure at some point or another. It must have something to do with the lifetime of the
IntoJs
andFromJs
traits, which I'd set in the method's signature. But I can't figure out what I'd have to change to make this work. Maybe the design ofrquickjs
simply doesn't allow for this kind of usage... I'm a little out of my depth here and it would be awesome if someone could help me out here!