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
I need to have a button that mutates some data, under the context of a state manager. I wrote a simple state manager that works kind of like a state machine with changes in state happening through navigating the UI, and some functions related to mutating the data requires a mutable reference to self, which requires a mutable variable and a mutable reference, which cannot be obtained inside a plain Fn. Is there a way around this:
Note: I did try wrapping it in an Rc of Cell, it did work until I encountered closure may outlive the current function, but it borrows \state manager variable name`, which is owned by the current function.Usingmove would work, but one would need to make a different clone of theRc` per closure, which is kind of clunky.
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
-
I need to have a button that mutates some data, under the context of a state manager. I wrote a simple state manager that works kind of like a state machine with changes in state happening through navigating the UI, and some functions related to mutating the data requires a mutable reference to self, which requires a mutable variable and a mutable reference, which cannot be obtained inside a plain
Fn
. Is there a way around this:Note: I did try wrapping it in an
Rc
ofCell
, it did work until I encounteredclosure may outlive the current function, but it borrows \
state manager variable name`, which is owned by the current function.Using
movewould work, but one would need to make a different clone of the
Rc` per closure, which is kind of clunky.Beta Was this translation helpful? Give feedback.
All reactions