semisafe 0.1.0

Semi-safe utilities for performance-critical Rust
Documentation
/// Returns success value inside `res` without `Err` checks in release builds.
///
/// Use this only when surrounding code guarantees that `res` is `Ok(_)`.
/// In debug builds this delegates to [`Result::unwrap`] so invariant
/// violations panic with error value. In release builds, passing `Err(_)`
/// causes undefined behavior.
///
/// # Panics
///
/// Panics in debug builds if `res` is `Err(_)`.
///
/// # Examples
///
/// ```
/// let value = semisafe::result::unwrap::<_, &str>(Ok(42));
/// assert_eq!(value, 42);
/// ```
#[inline(always)]
pub fn unwrap<T, E: std::fmt::Debug>(res: Result<T, E>) -> T {
    #[cfg(debug_assertions)]
    {
        res.unwrap()
    }

    #[cfg(not(debug_assertions))]
    {
        unsafe { res.unwrap_unchecked() }
    }
}