4 ms·
> Unsafe Rust is not automatically bad Correct me if I'm wrong, but isn't one of the main selling points of Rust that's it's "safe"? If you're using "unsafe" R
by capableweb 5y ago
> Unsafe Rust is not automatically bad
Correct me if I'm wrong, but isn't one of the main selling points of Rust that's it's "safe"? If you're using "unsafe" Rust, you might just go for more established languages straight up.
- Kinrany 5y agoThe unsafety is localized to the rare `unsafe` blocks, which are not allowed to compromise the safety of the rest of the program.
- jokethrowaway 5y agoYou can still have the compilers check a few things, even in unsafe code. Besides, having 95% safe code and 5% unsafe code is still going to help when working on the rest of the codebase
- akiselev 5y agoRust's main selling point is a type system that allows safe wrappers around unsafe code by encoding invariants in the types themselves. Stuff that lives in the documentation like "you need to call foobar_free" becomes an unsafe block in a safe Drop implementation that only needs to be extensively tested once to validate the safety of the wrapper. Once the safe-unsafe interface is tested, downstream code doesn't have to worry about the unsafe implementations at all. Without unsafe, Rust programs would be useless since the Rust compiler can't verify the safety of external libraries that provide critical functionality like memory allocation and syscal interfaces (I/O). It would also go against one of Rust's main goals which is C FFI compatibility, which is something that the Rust compiler can't verify.