To ensure memory and thread safety, Rust's borrow checker has three simple rules. They are enforced all through the code except in unsafe scopes. Here they are:
- Each binding will have an owner
- There can only be one owner for a binding
- When the owner goes out of the scope, the binding gets dropped
These three rules seem simple enough, but they have a great implication on how we code. The compiler can know beforehand when an owner goes out of scope, so it will always know when to drop/destruct a binding/variable. This means that you can write your code without having to think about where you create variables, where you call destructors, or whether you have already called a destructor or you are calling it twice.
Of course, this comes with an additional learning curve that can sometimes be difficult to catch up. The second rule is what most people...