When using closure in wasm gives error that pointer is not a function

while using closure to bind to a event with web-sys gives error of the pointer not being a function


use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use web_sys::{

code function

    let mut bool = false;
    let closure = Closure::wrap(Box::new(move |event: MouseEvent| {
        bool = true;
        console::log_1(&"mouse moved".into());
    }) as Box<dyn FnMut(_)>);

error : firefox

TypeError: wasm._dyn_core__ops__function__FnMut___A____Output___R_as_painter_wasm_controller__closure__WasmClosure___describe__invoke__h7d5c063429d40c38 is not a function

what am i doing wrong

I don't have your answer, but that looks like an error that would occur in the output of a macro.

what do you mean can you please share how to investigate it further please??

Well it seems like Javascript doesn't think your boxed FnMut is a function.

yes i figured that out have you used closures yet in any project with wasm?? if so did you encounter any problem is the syntax correct??

I have not used wasm, but it is the right syntax for closures in other situations. I would investigate the documentation on Closure, and the unchecked_ref and set_onmouseenter methods first. Perhaps also the forget call.

1 Like

thanks i figured it out it was a bug.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.