Skip to content
Discussion options

You must be logged in to vote

Right you're trying to mutate a variable (handle_ownership) that's not declared mutable. If you add mut it will also be sad because now you're mutating a captured variable in an Fn closure. We should probably allow FnMut on event listeners like that in the future but in any case adding a RefCell here works fine:

let handle_ownership = RefCell::new(Some(mouse_move));

let mouse_up = window_event_listener(ev::mouseup, move |e| {
    if let Some(k) = handle_ownership.borrow_mut().take() {
        k.remove();
    }

    log!("Mouse Up");
});

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
1 reply
@ekanna
Comment options

Comment options

You must be logged in to vote
6 replies
@ekanna
Comment options

@gbj
Comment options

gbj Nov 14, 2023
Maintainer

@ekanna
Comment options

@gbj
Comment options

gbj Nov 14, 2023
Maintainer

Answer selected by ekanna
@ekanna
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants