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

Why do all examples clone() and move all values into callbacks? #68

Open
tobia opened this issue Apr 3, 2019 · 3 comments
Open

Why do all examples clone() and move all values into callbacks? #68

tobia opened this issue Apr 3, 2019 · 3 comments
Labels
c-question Further information is requested p-high High Priority x-help wanted Extra attention is needed

Comments

@tobia
Copy link

tobia commented Apr 3, 2019

I noticed that all examples clone() and move all values into the callbacks, including the ui context and all controls. In the case of inptus.rs, the mutable application state is wrapped in a Rc (over the RefCell) to be able to clone() and move several references into the callbacks.

I tried removing all of this overhead, just passing around simple read-only references, and everything seems to work the same (on Linux.)

What is the reason for adding those operations to the examples? Could you add a paragraph of documentation to the README explaining this choice?

In case it is needed to avoid problems and/or cross-platform compatibility, could you make it so that forgetting to do it would cause a compilation error? It seems an easy thing to forget, especially since everything seems to be working the same.

@NoraCodes
Copy link
Collaborator

NoraCodes commented Apr 3, 2019 via email

@tobia
Copy link
Author

tobia commented Apr 3, 2019

Ok thank you.

While we are on the topic of clone(), I see that the layout methods such as append() still take a direct moved value child: T, so in these calls one is still supposed to clone() the children to be added?

@tobia
Copy link
Author

tobia commented Apr 3, 2019

There's still much I don't understand. I successfully removed all clone() and move from the callbacks in inputs.rs, except for the one in on_tick(), which gives a lifetime error if I try to get rid of move.

Then I tried removing the Rc wrapper, leaving only the RefCell, and I get a result I don't understand. The code compiles and runs without errors, but the various callbacks seem to access different copies of the state object! I don't understand where those copies come from!

@NoraCodes NoraCodes added c-question Further information is requested p-high High Priority x-help wanted Extra attention is needed labels Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-question Further information is requested p-high High Priority x-help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants