-
-
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
Not sound to use lifetimes in function signatures #1187
Comments
Thanks for the report! This is one I don't think we've given a ton of thought to just yet, but I suspect that with some work we could get |
Thanks for the feedback! What I ended up doing instead is changing my |
@attente i am agree this. when i learn rust, the rust-book tell me how important about the |
The same issue I encountered. I suspect that wasm-bindgen do not support static lifetime yet either. |
So, I want to know When this bug will be fixed. Thanks a lot. |
wasm-bindgen does not allow `&'static` or any other lifetimes for exported bindings (rustwasm/wasm-bindgen#1187), so needed to switch tags to owned Strings.
same probleme here, I'm passing a js cloure to wasm, the complier tells me to add |
wasm-bindgen does not allow `&'static` or any other lifetimes for exported bindings (rustwasm/wasm-bindgen#1187), so needed to switch tags to owned Strings.
wasm-bindgen does not allow `&'static` or any other lifetimes for exported bindings (rustwasm/wasm-bindgen#1187), so needed to switch tags to owned Strings.
This is because wasm-bindgen does not support 'static for function Pleaase see rustwasm/wasm-bindgen#1187
This is because wasm-bindgen does not support 'static for function Pleaase see rustwasm/wasm-bindgen#1187
* feat: Add numberings * feat: Use String for wasm This is because wasm-bindgen does not support 'static for function Pleaase see rustwasm/wasm-bindgen#1187
@oHaiyang did you find any solution or workaround for the closure problem? |
I'm also bit by this as I have data structures that have a lifetime on them. Even though I can support a static lifetime, I can't actually return them. An example (untested) of the issue I'm encountering: #[wasm_bindgen]
#[derive(Serialize, Deserialize)]
pub struct SomeStruct<'a> { ... }
#[wasm_bindgen]
pub fn get_some_struct() -> SomeStruct<'static> {
// Make a static instance
SomeStruct { ... }
} I can get around this by providing a wrapper type that contains the static instance, although I still have to convert to a #[wasm_bindgen]
pub struct Output(Page<'static>);
#[derive(Serialize, Deserialize)]
pub struct SomeStruct<'a> { ... }
#[wasm_bindgen]
impl Output {
pub fn to_js(&self) -> JsValue {
JsValue::from_serde(&self.0).unwrap()
}
} |
I wanted to avoid passing around instances of core structs so much, and just initialize one with an instance of another, but wasm-bindgen doesn’t fully support Rust lifetimes yet so this wasn’t possible. rustwasm/wasm-bindgen#1187
+1 for this feature, thanks! |
Came across rustwasm/wasm-bindgen#1187 and eventually found a way around it. Things are still looking quite ugly but at least I'm moving forward.
I'm also struggling with this. I have a kind of like: pub fn parse<'a>(input: &'a str) -> Result<Vec<Token<'a>>, ParseError> {} any idea how can I create a wasbindgen for this case? thanks! |
I got the following to compile:
You should take the above with several pinches of salt:
I hope this helps you. Feel free to let me know the outcome. |
Seems like wasm-bindgen prohibits the use of lifetime specifiers in certain places where the compiler requires them. I have a test repo here: https://github.com/attente/wasm-bindgen-lifetime-issue
Building it, the error is:
Unfortunately if I remove the
'static
lifetime specifier, then the compiler will complain:Is there any workaround for this issue?
The text was updated successfully, but these errors were encountered: