Open ApoorvaJ opened 5 years ago
I've figured out how closures work, and how to work with websockets, but I think that some things need better explanation:
JsValue
, Function
and a Closure
.Closure
pattern is required, and what Closure.forget()
means.add_event_listener...
functions work.set_on*
functions such as WebSocket::set_onopen()
.web_sys::MouseEvent
, that would be helpful. Currently we have to do a lot of ping-ponging between web_sys docs and MDN.clone()
things as required.
The current documentation on closures requires a lot of prior knowledge of Rust, closures, and of this library. The relationship between
JsValue
,Function
and aClosure
isn't properly explained. An understanding ofFn
andFnMut
is also assumed.I spent quite a lot of time fighting the borrow checker because my values would be moved into the closure. Without closures, I understand the Rust borrow checker pretty well, and I have done significant systems programming in the past, so the Rust model lines up with good C code. But this understanding breaks with closures.
Additionally, the documentation doesn't discuss how to get values in closures that would be passed into Javascript event callbacks, e.g.
How do I get
msg
in Rust-land?Having a WebSocket example such as the one stdweb has would be a nice illustration of the websocket APIs, and coupled with a better explanation of closures, would also clarify that matter greatly.