Skip to content
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

Closure FnMut #202

Open
JamyGolden opened this issue Jul 22, 2024 · 1 comment
Open

Closure FnMut #202

JamyGolden opened this issue Jul 22, 2024 · 1 comment

Comments

@JamyGolden
Copy link

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
Copy link
Owner

FnOnce is surprising.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants