I having issue on my rust codes
I have a struct A, a method B of this struct who received a mutable self, and inside this method I create a closure that needs also to receive a mutable reference to A. Smth like this:
What's the best way to do this? I can use several Arcs, but then it could get messy
struct A {}
impl A {
pub fn B(&mut self) {
self.something(|| {
self.other_method_required_mutable();
});
}
}What's the best way to do this? I can use several Arcs, but then it could get messy
No any search results
You already invited:
3 Answers
ravi Gupta
Upvotes from:
shangels
Upvotes from:
yakitoriPB
Upvotes from:
The only other way I see is to provide &mut self back into closure as argument
struct A {}This will only work if you don't borrow any parts of self inside something at the moment you call provided closureimpl A {
pub fn B(&mut self) {
self.something(|this| {
this.other_method_required_mutable();
});
}
}