I think few categories undersells it. Just having Optional/Maybe in a language legitimately does make bugs disappear.
Segfaults are only one of many ways for software to go wrong.
In Rust’s case, I take it as a promise not to do anything memory-unsafe. Lapce did not keep this promise when I tried it.
But there’s bound to be unsafe code somewhere in a complex enough project.
EDIT: IOW, why don't projects just eschew unsafe in order to truly leverage one of Rust's primary claims to fame?
Sticking to safe rust is an ideal and it should be a goal but the primary use is to accomplish a task. If safe rust is getting in the way and there’s no way to do it easily otherwise, don’t feel bad about unsafe. The amount of unsafe should be minimized of course which reduces the surface area of issues greatly compared with c/C++ where every line is unsafe. Practical code is always >> ideological purity.
Like, if I'm doing x + y, and y just accidentally happens to contain the wrong data because of a mistake in the code, a NaN means the code will proceed as normal, and nobody will notice anything is wrong. If it's not a noticeable bug, it might be a long time until it's spotted by someone. And when they do, who knows how much damage it will have caused.
As a program author, I'd expect that it's my choice how to handle this situation. I don't want libraries making arbitrary decisions about how my code should work.
#[repr(f32)]
enum Float32 {
PositiveInfinity,
NegativeInfinity,
Nan(NanPayload32),
Finite(FiniteFloat32),
}
You could also then define NonNanFloat32 etc which could be used for certain operations. Of course on machine level its all the same