3 ms·
Unsafe Rust is not automatically bad. The main reason all of those major libraries got switched to safe Rust is that progress in language features made it possi
by whatshisface 6y ago
Unsafe Rust is not automatically bad. The main reason all of those major libraries got switched to safe Rust is that progress in language features made it possible to do the same operations safely.
- lampe3 6y agoI don't wanted to imply that unsafe rust is bad. The argument was that you can disable it easily. For good and bad reasons.
- capableweb 6y 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 6y agoThe unsafety is localized to the rare `unsafe` blocks, which are not allowed to compromise the safety of the rest of the program.
- jokethrowaway 6y 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 6y 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.