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

The ui.data() requires mutable borrow to get_temp()? #2741

Closed
IS2511 opened this issue Feb 15, 2023 · 0 comments · Fixed by #2742
Closed

The ui.data() requires mutable borrow to get_temp()? #2741

IS2511 opened this issue Feb 15, 2023 · 0 comments · Fixed by #2742
Labels
bug Something is broken

Comments

@IS2511
Copy link
Contributor

IS2511 commented Feb 15, 2023

Describe the bug

It seems that inside the ui.data() lambda I can't get_temp() anything from the IdTypeMap because the reference to it passed to the lambda apparently needs to be mutable. Why?

To Reproduce
Steps to reproduce the behavior:

  1. Create an eframe project and plop down some widget
  2. Inside the lambda that accepts &mut egui::Ui do
let x_id = ui.id().with("x");
let x = ui.data(|d| d.get_temp::<u32>(x_id).unwrap_or_default());
error[E0596]: cannot borrow `*d` as mutable, as it is behind a `&` reference
  --> [DATA EXPUNGED].rs:41:33
   |
41 |             let x = ui.data(|d| d.get_temp::<u32>(x_id).unwrap_or_default());
   |                              -  ^^^^^^^^^^^^^^^^^^^^^^^ `d` is a `&` reference, so the data it refers to cannot be borrowed as mutable
   |                              |
   |                              consider changing this binding's type to be: `&mut IdTypeMap`

Expected behavior

Since get_temp() clones the value, the IdTypeMap is not required to be mutable. Applies to all "read" methods.

Screenshots

Desktop (please complete the following information):

  • OS: Linux 5.18.0-14parrot1-amd64 #1 SMP PREEMPT_DYNAMIC Debian 5.18.14-1parrot1 (2022-08-07) x86_64 GNU/Linux
  • Browser
  • Version master (7215fdf)

Additional context

Am I missing something? This seems very weird.

Possibly related:

@IS2511 IS2511 added the bug Something is broken label Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant