62 ms·
> Now its that you have to just make sure all your code is > correct, not just the unsafe blocks. You appear to be misunderstanding the article, which likel
by kibwen 11y ago
> Now its that you have to just make sure all your code is
> correct, not just the unsafe blocks.
You appear to be misunderstanding the article, which likely explains all the downvotes.
Rust keeps you from doing memory-unsafe operations unless you use an `unsafe` block somewhere. Once you do, then it is your duty to ensure that those `unsafe` blocks don't cause memory unsafety, regardless of what the rest of your program does. Following from that, if the correctness of your `unsafe` block relies on invariants in your data, then it is your duty to keep your data private so that those invariants cannot be broken by consumers (or alternatively, provide safe accessor functions that allow consumers to fiddle with things while performing runtime checks to ensure invariants are upheld).