// Copyright 2020 Amari Robinson // // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be // copied, modified, or distributed except according to those terms. use core::hint; /// An extension trait on `Option`. pub trait UncheckedOptionExt { /// Returns the contained value. /// /// # Safety /// /// It is up to the caller to guarantee that the `Option` is `Some(v)`. /// Calling this when it is `None` causes undefined behavior. unsafe fn unwrap_unchecked(self) -> T; } impl UncheckedOptionExt for Option { #[inline] unsafe fn unwrap_unchecked(self) -> T { match self { Some(x) => x, None => { if cfg!(debug_assertions) { unreachable!() } else { hint::unreachable_unchecked() } } } } }