-
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
Allow using 'static
lifetimes in functions
#3856
Conversation
f2e1ceb
to
97fe5df
Compare
97fe5df
to
0338634
Compare
This applies to arguments too, where using use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn invalid(_: &'static str) {}
LGTM if you're okay with that though. |
Also, this fixes #1187 (the thing it was originally opened for anyway, not the struct use case someone brought up later). |
Co-Authored-By: Liam Murphy <43807659+Liamolucko@users.noreply.github.com>
I'm fine with that considering its the same error message you already get when doing: #[wasm_bindgen]
pub fn invalid(_: &str) {} What kind of references are actually allowed in exported functions? Otherwise I could go ahead and outright ban them. |
What do you mean? That example compiles just fine.
Up until now, just the kind above, and I assumed the whole point of this PR was to allow ones like this: #[wasm_bindgen]
pub fn foo() -> &'static str {
"hello world"
} I didn't test it thoroughly enough and that actually still doesn't compile because of an extra error ('cannot return a borrowed ref with #[wasm_bindgen]'), but it now works if you wrap it in something: #[wasm_bindgen]
pub fn foo() -> Option<&'static str> {
Some("hello world")
} That's also the use-case #1187 was asking for (although it should probably be reopened now that I've realised this doesn't fully fix it). |
Yep, my mistake.
Sorry, should have probably mentioned this in OP. My problem was just lifetimes in pointers as parameters, e.g.
I've re-opened it. My PR's have been pretty sloppy lately, so thank you for your diligent and careful reviews! |
This reverts commit b9ccb8f.
Currently
#[wasm_bindgen]
disallows any kind of lifetime on functions.This change allows it to accept
'static
.Fixes #1187.