Transformed event-loop callback to FnMut to allow mutable values#2667
Conversation
lucasfernog
left a comment
There was a problem hiding this comment.
looks good, can you add a change file? there's some examples on the .changes folder
|
@lucasfernog Done. I am not familiar with the (I just realized that I had opened the documentation on this but forgot to read it and checked the box anyway in my PR: sorry about that). Please let me know if I made a mistake. |
|
The .changes folder is a covector thing, it allows us to define changes on each crate, which turns into an automated changelog. So yeah it should describe changes on all crates. |
|
@lucasfernog Thanks for the explanations. That makes sense. I just updated my last commit to include the missing crates. |
|
Thanks, nice work :) |
|
در دوشنبه ۲۷ سپتامبر ۲۰۲۱ در ۲۱:۰۴ Lucas Fernandes Nogueira <
***@***.***> نوشت:
Thanks, nice work :)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2667 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AU3VN7ENND6NT75AEZZ6LT3UECTMFANCNFSM5E23HIHQ>
.
--
null
|
|
So I just added the missing changes for Windows too. I get remaining a test failure that I'm not sure I understand: Looking at the array, the difference seems to be about the expected binary to contain Windows line-endings ( Not sure if this is a problem and how to fix it. |
|
Seems unrelated, let's ignore that one for now. |
|
Aside from the timeout, which I'm not sure is related to these changes, everything seems to be passing! |
|
Yeah the timeout is just GH action and Rust being slow :) thanks for the PR! |
What kind of change does this PR introduce?
Does this PR introduce a breaking change? (check one)
The PR fulfills these requirements:
fix: #xxx[,#xxx], where "xxx" is the issue number)Other information:
Hi,
This PR fixes a limitation in Tauri's current callback design.
This Rust Playground example illustrates the problem.
Right now, Tauri's event loop callbacks are
dyn Fn(RunEvent) + 'staticwhich doesn't allow the caller to move-in mutable values. As this callback is typically provided for callers to be able to update their own event/game loop, and as these update methods are usually marked&mut self, the callers have no choice but to wrap their values in aRc<RefCell<T>>, and to callborrow_mut()for each event.Aside from the additional code required, it forces heap-usage and causes some extra-work for each iteration (granted: this is not a lot of work, but still: there is probably no good reason to have that extra-work when a simple change can avoid it).
The proposed changes make it possible for callers to simple move the mutable value in the callback and call it directly.
Let me know what you think of this, and I'll be happy to discuss it of course!
P.S: Thanks for all the good work on Tauri: it is an awesome project.