on Sat, Apr 23, 2016 by Neil Shen · 1 min reading time
- [References and Borrowing]
You may have one or the other of these two kinds of borrows, but not both at the same time:
- one or more references (&T) to a resource,
- exactly one mutable reference (&mut T).
[Rust Means Never Having to Close a Socket]
[Wrapper Types in Rust: Choosing Your Guarantees]
[Fearless Concurrency with Rust]
In Rust, having &mut access to the relevant locations at the same time guarantees atomicity of updates to them, since no other thread could possibly have concurrent read access.
Rust instead uses ownership and borrowing to provide its two key value propositions:
- Memory safety without garbage collection.
- Concurrency without data races.