Hello,
This question is related to this previous one: Best way to hide borrow_mut - #5 by Alphapage
Here is my new code:
pub struct A {
pub b: Arc<Mutex<B>>,
}
pub struct B {
field: C,
}
pub struct C;
trait Update {
fn update(&mut self, text: C);
}
impl Update for B {
fn update(&mut self, text: C) {
self.field = text;
}
}
impl Update for Arc<Mutex<B>> {
fn update(&mut self, text: C) {
self.lock().unwrap().field = text;
}
}
pub fn try_() {
let mut a = A {
b: Arc::new(Mutex::new(B { field: C {} })),
};
let closure: Box<dyn Fn()> = Box::new(move || {
a.b.update(C {});
});
}
I must use a.b.lock().unwrap().update(C {});
(or change to FnMut
but this is no what I want).
I don't understand why it doesn't compile because it is doing the same thing finally!
Is there a workaround ?
Thank you in advance for your help.