Skip to content

Banging my head against this #4170

Answered by bjorn
Tsuiban asked this question in General
Dec 17, 2023 · 2 comments · 6 replies
Discussion options

You must be logged in to vote
  1. It seems that I need to create a weak reference for EACH callback, so multiple variables instead of one single one.

I see this mostly as a shortcoming of Rust, since it appears lambdas can only use references (the default) or move values (when writing move ||, whereas C++ provides [=] { to create a lambda based on copies. To avoid the annoying creation of variables like ui_1, ui_2, etc. I have gotten into the habit of using this nice Rust feature (not sure what to call it):

ui.on_request_name_accepted({ let ui = ui.as_weak(); move || { let model = ui.unwrap().get_model_property(); println!("{model:?}"); }});
ui.on_request_start_accepted({ let ui = ui.as_weak(); move || { let model = ui.

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

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

@Tsuiban
Comment options

@tronical
Comment options

@ogoffart
Comment options

@bjorn
Comment options

Answer selected by Tsuiban
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants