News for hackers. Stuff that matters.
Re:Cloudflare outage on November 18, 2025 post mortem by cherryteastain on Tuesday November 18, 2025 @08:40PM (#45974862)
Rust's Result is the same thing as C++'s std::expected. How is calling std::expected::value undefined behaviour?
Re:Cloudflare outage on November 18, 2025 post mortem by gpm on Tuesday November 18, 2025 @08:49PM (#45974929)
Rust's foo: Option<&T> is rust's rough equivalent to C++'s const T* foo. The C++ *foo is equivalent to the rust unsafe{ *foo.unwrap_unchecked() }, or in safe code *foo.unwrap() (which changes the undefined behavior to a panic).

Rust's unwrap isn't the same as std::expected::value. The former panics - i.e. either aborts the program or unwinds depending on context and is generally not meant to be handled. The latter just throws an exception that is generally expected to be handled. Panics and exceptions use similar machinery (at least they can depending on compiler options) but they are not equivalent - for example nested panics in destructors always abort the program.

In code that isn't meant to crash `unwind` should be treated as a sign saying that "I'm promising that this will never happen", but just like in C++ where you promise that pointers you deference are valid and signed integers you add don't overflow making promises like that is a necessary part of productive programming.

Re:Cloudflare outage on November 18, 2025 post mortem by 9029 on Tuesday November 18, 2025 @09:16PM (#45975107)
Tangential but funnily enough calling std::expected::error is ub if there is no error :D