Hacker News new | ask | show | jobs
by tialaramex 776 days 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)

1 comments

I see. I didn't know that method existed despite spending ~4.5 years writing Rust.
Ha, same. I very very rarely write code in unsafe contexts which is why, I guess.