fn high_word(n: u32) -> u16 {
(n >> 16).try_into().unwrap()
}
Unless someone manages to solve the halting problem, we'll always need unwrap() or equivalent. fn high_word(n: u32) -> u16 {
(n >> 16).try_into().unwrap()
}
Unless someone manages to solve the halting problem, we'll always need unwrap() or equivalent.See: https://play.rust-lang.org/?version=nightly&mode=release&edi...
Where if you look at the asm for playground::high_word then you'll see it's a bare shrl.
I'd quite like an analogue to unwrap() that's checked at compile time -- an out for the type checker, but an error if it's not dead code eliminated. This helps us to trust and rely on the compiler, and is the converse of `unsafe_unwrap`, which tells the compiler to trust us.
There is also this thing called "Infallible". Which will eventually be merged with "!". To express to the compiler and the programmer that something can never fail.
I’d be thrilled if C++ required wrapping declaration and use of global variables with ‘unsafe_and_evil { … }’