-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should lifetimes on JS values be supported #423
Comments
I find that the most natural way to expose lifetimes to JS is to take a JS callback and say "the data passed to this callback may only be used while the call is active". This is not always super Rust-y, and not always applicable, but it is generally clear how to use the thing correctly from the JS side. When JS owns something that borrows something else, it gets more difficult. At the end of the day, FFI'ing with JS is always going to be unsafe, but our goal is to make the Rust side correct and easy. JS doesn't have borrowck, so lifetimes obviously can't improve the JS side, but they can improve the Rust side, and therefore are worthy of pursuit. |
I have a similar issue, this surrounding stack-lifetime callbacks inside of an options object. The problem there is, I have a class in JS like class Foo {
function totalCost(opts) { ... }
} and inside the opts object is a cost function. What I'd like to do is be able to place a non- #[wasm_bindgen]
struct Options<'a> {
cost_fn: &'a mut dyn FnMut(String) -> u32
} but that fails to compile. In the meanwhile I've been using a helper module with a function that takes the partial options object and the callback as a parameter, puts the callback into the options, and calls |
I believe we should at least deprecate or potentially remove all these functions, as they are actually Alternatives method signatures, by passing |
This first came up on #419, but one web API looks (sort of) like this:
Here we're creating an
ImageData
while also passing a buffer of memory to its contructor. Presumably anImageData
retains a handle to the array passed in to later get rendered, which means that the lifetime of theImageData
instance produced is actually tied to the&[u8]
passed in.Normally in Rust this would be expressed through lifetimes, something like:
but that's not supported by
#[wasm_bindgen]
today!Should we somehow add support for these lifetimes? Or would this perhaps make web APIs too difficult to use? Should we instead leave-as is where you probably won't get a segfault but you'd get weird results sometimes?
The text was updated successfully, but these errors were encountered: