Crate unsafe_unwrap [] [src]

Provides a way to quickly yet unsafely unwrap types whose inner values are known to exist.

By calling unsafe_unwrap(), the compiler is told, in optimized builds, that the unwrap will never fail. In debug builds it will emit a panic.

Sometimes the optimizer can remove checked unwrapping if it can prove that a value exists. However, in times that it may not be able to do so, this works as an alternative.

This is akin to the unsafelyUnwrapped property of Optional in Swift.


use unsafe_unwrap::UnsafeUnwrap;

let x = Some(20);
let y = unsafe { x.unsafe_unwrap() };



A type whose instances can be unsafely unwrapped without checking.