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
But using the online demo to see the generated rust code for export, the apply-events method takes &self. But what if I want to mutate self with &mut self, is this possible?
This is currently due to the assumption that components allow for being recursively entered. This means that if Rust handed out &mut T then it would be memory unsafe to recursively call the component. This means that there's no way to use &mut self and you need to use interior mutability such as Cell<T> or RefCell<T>.
I believe the most recent iteration of the component model disallows recursively entering a component, though, so a future iteration of wit-bindgen for the updated component model will likely define all methods with &mut self since you'll have exclusive access at all times.
Oh right! Thanks for all the info.
For now I'll use Cell or RefCell, and with that update I guess I can easily modify my code to use &mut self instead.
I truly appreciate the hard work you guys are doing. Feel free to close this issue if you think it's not needed, or it can be kept open as a tracker until &mut self.
Activity
alexcrichton commentedon Mar 21, 2022
This is currently due to the assumption that components allow for being recursively entered. This means that if Rust handed out
&mut Tthen it would be memory unsafe to recursively call the component. This means that there's no way to use&mut selfand you need to use interior mutability such asCell<T>orRefCell<T>.I believe the most recent iteration of the component model disallows recursively entering a component, though, so a future iteration of wit-bindgen for the updated component model will likely define all methods with
&mut selfsince you'll have exclusive access at all times.tqwewe commentedon Mar 21, 2022
Oh right! Thanks for all the info.
For now I'll use Cell or RefCell, and with that update I guess I can easily modify my code to use
&mut selfinstead.I truly appreciate the hard work you guys are doing. Feel free to close this issue if you think it's not needed, or it can be kept open as a tracker until
&mut self.alexcrichton commentedon Mar 21, 2022
Ok I'll leave this open so when we see this again I can confirm that this change was made or not.
alexcrichton commentedon Apr 20, 2022
Ok I'm going to close this in favor of #201 since this is part of the new canonical ABI updates.