by void_mint · 5y ago · 0 comments
If the argument is "You can use unsafe but do things safely", isn't that the same argument as C? "Just have faith that they did it right"?
For example, you wish to implement a Vector in Rust.
You generally don't want to allocate that Vector over and over, so you request more memory than you need.
That "extra" memory is uninitialized which is a big no-no in Rust. You might be able to initialize that memory, but that will have performance implications that C/C++ programmers would just laugh at.
However, your "invariant" is that you never access that memory until you have a real element that you put there. That's perfectly fine.
Nevertheless, accessing that uninitialized area will always be "unsafe" from the Rust compiler point of view.