4 ms·
> "unsafe" is expressing that you are opting-in for less safe code. Same in C#. Yes, but that is scoped. You can write unsafe code when designing an abstractio
by Manishearth 10y ago
> "unsafe" is expressing that you are opting-in for less safe code. Same in C#.
Yes, but that is scoped. You can write unsafe code when designing an abstraction, and seal off the unsafety with a safe-to-use API. You then verify the abstraction, and are free to use it however you want. This is what's usually done, and this is what unsafe is for.
"mut" isn't really a red-flag keyword. Sure, you don't want unnecessary mutation and everything is immutable by default, but nobody really has issues with making things mutable. Rust is not a language where purity is important.
"unsafe" is, but for designing abstractions that's what unsafe is for, and while you still should justify it, "I need an abstraction like this and it can't be implemented in safe Rust because <reasons>" should be enough. Of course, you should be able to explain why it is safe to use, preferably in the docs/comments.
- partycoder 10y agoNo but "mut" comes with a maintenance cost. Where it is harder to make assumptions over its value.