Skip to main content

osom_lib_macros/
lib.rs

1//! This crate defines various macros for osom libraries.
2//!
3//! The crate is `#![no_std]`.
4#![deny(warnings)]
5#![allow(unused_features)]
6#![warn(clippy::all, clippy::pedantic)]
7#![allow(clippy::inline_always)]
8#![no_std]
9
10/// Checks the condition in debug mode, but claims it is true in release mode.
11#[macro_export]
12macro_rules! debug_check_or_release_hint {
13    ($condition:expr) => {
14        #[cfg(debug_assertions)]
15        {
16            assert!($condition);
17        }
18
19        #[cfg(not(debug_assertions))]
20        unsafe {
21            core::hint::assert_unchecked($condition);
22        }
23    };
24    ($condition:expr, $msg: literal) => {
25        #[cfg(debug_assertions)]
26        {
27            assert!($condition, $msg);
28        }
29
30        #[cfg(not(debug_assertions))]
31        unsafe {
32            core::hint::assert_unchecked($condition);
33        }
34    };
35}