xxxxxxxxxx
If we try to violate these rules, rather than getting a compiler error as we would with references, the implementation of RefCell<T> will panic at runtime.
We’re deliberately trying to create two mutable borrows active for the same scope to illustrate that RefCell<T> prevents us from doing this at runtime.
//+//let mut one_borrow = self.sent_messages.borrow_mut();
//-//let mut two_borrow = self.sent_messages.borrow_mut();
xxxxxxxxxx
let mut base_3 = base.borrow_mut();
base_3.radio_freq += 43.21; //** main issue. you need to define this line in interior block like line scope 7 so line 2 is wrong when placed in main scope
println!("base: {:?}", base);
println!("base_3: {:?}", base_3);
{
let mut base_4 = base.borrow_mut();//'already borrowed: BorrowMutError'
base_4.radio_freq -= 3.52;
println!("base_2: {:?}", base_4);
}
/*
base: RefCell { value: <borrowed> } //**
base_3: GroundStation { radio_freq: 118.52000000000001 }
thread 'main' panicked at 'already borrowed: BorrowMutError'
*/