You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update: I found the solution: give references have different--and thus, allowed to be shorter--lifetimes than their referencees. I've update the code below to have the additional explicit lifetimes.
We're using egui in an MVVM app's View. I'd like to pass in a callback for our widgets to propagate user responses to the ViewModel. However, we're getting a lifetime issue (error below).
Is there a pattern egui users use to implement callbacks like this, or am "just" overlooking some obvious-to-the-more-experienced way of finessing the lifetimes to let rustc know that the borrow in question has a short enough lifetime after being passed down through the structs and method calls of our methods and widgets?
180 | let c = ViewUpdateContext {
| - binding `c` declared here
...
188 | .show(ctx, |ui| {
| ---- value captured here
189 | self.build_main_ui(ui, &c);
| ^ borrowed value does not live long enough
190 | }).inner;
191 | }
| -
| |
| `c` dropped here while still borrowed
| borrow might be used here, when `c` is dropped and runs the destructor for type `ViewUpdateContext<'_>`
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Update: I found the solution: give references have different--and thus, allowed to be shorter--lifetimes than their referencees. I've update the code below to have the additional explicit lifetimes.
We're using egui in an MVVM app's
View
. I'd like to pass in a callback for our widgets to propagate user responses to theViewModel
. However, we're getting a lifetime issue (error below).Is there a pattern egui users use to implement callbacks like this, or am "just" overlooking some obvious-to-the-more-experienced way of finessing the lifetimes to letrustc
know that the borrow in question has a short enough lifetime after being passed down through the structs and method calls of our methods and widgets?Many thanks!!!
Very cut-down code sketch:
In
view.rs
:...
In
view/icon.rs
:Error:
Beta Was this translation helpful? Give feedback.
All reactions