chinedufn / percy

Build frontend browser apps with Rust + WebAssembly. Supports server side rendering.
https://chinedufn.github.io/percy/
Apache License 2.0
2.26k stars 84 forks source link

Closure FnMut #202

Open JamyGolden opened 1 month ago

JamyGolden commented 1 month ago
let end_view = html! { <label onclick=|event: MouseEvent| {
    state.set_dimensions((12 as usize, 15 as usize));
}> }

pdom.update(end_view);

I get an error with this:

Diagnostics:
expected a closure that implements the `FnMut` trait, but this closure only implements `FnOnce`
required for the cast from `std::rc::Rc<std::cell::RefCell<{closure@project/src/lib.rs:56:36: 56:55}>>` to `std::rc::Rc<std::cell::RefCell<(dyn std::ops::FnMut(percy_dom::event::MouseEvent) + 'static)>>` [E0525]

I don't get an error if I simply log information. Is there state mutation examples in the docs and I just haven't been able to find it?

chinedufn commented 1 week ago

FnOnce is surprising.

Does .set_dimensions take ownership of the receiver (self) instead of a mutable reference to the receiver&mut self?