16 ms·
You don't have to write this, it already exists as the (unsafe of course) method Option::unwrap_unchecked Because all Rust's methods can be called as free func
by tialaramex 3y ago
You don't have to write this, it already exists as the (unsafe of course) method Option::unwrap_unchecked
Because all Rust's methods can be called as free functions, you can literally write Option::unwrap_unchecked for the same behaviour, or you can some_option.unwrap_unchecked() (in both cases you will need to be in unsafe context for this to be allowed and should write a SAFETY comment explaining why you're sure it's correct)
- School-Cotton 3y agoI see. I didn't know that method existed despite spending ~4.5 years writing Rust.
- kaashif 3y agoHa, same. I very very rarely write code in unsafe contexts which is why, I guess.