The discussion of how borrowing impacts encapsulation, abstraction with private methods, and the observer pattern was informative and interesting.
In general terms although sometimes you need to do things like this, shared mutable state is something you should be avoiding in any language and you should thank Rust for making it harder on you.
It demonstrates a kind of getter, but a weird one since it returns a mutable field. These are not the most encapsulated thing.
Not in that case. It helps when dropping a borrow earlier avoids to violate the borrowing rules, like in this case:
let mut a = [0; 20];
{
let b = &mut a[2..4];
}
let c = &mut a[6..8];
In the example from the blog post, content borrows the whole struct, and you can't drop the borrow earlier since it is used in the next line.I think there’s a missing guide out there for people like myself who have an OO background, are looking to write some rust but can’t reconcile the borrow-checker with how they normally design software