I’m still learning Rust.
While reading this intro, I have a question:
Arc is Implemented by
unsafe, why we dont need to use
unsafe when using
If Rust makes it impossible to unsafely share data between threads, and Rust is written in Rust, then how does it implement concurrent types like
Mutex? The answer:
As I learned in TheBook.
In both unsafe functions and unsafe blocks, Rust will let you do three things that you normally can not do. Just three. Here they are:
- Access or update a static mutable variable.
- Dereference a raw pointer.
- Call unsafe functions. This is the most powerful ability.
Arc::New() is not a unsafe function?
But I imagine that
Arc should use some
unsafe magic to implement itself, how could it not be unsafe function?