diff options
Diffstat (limited to 'crates/utils')
-rw-r--r-- | crates/utils/src/lib.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/crates/utils/src/lib.rs b/crates/utils/src/lib.rs index 6e26317..c6681d9 100644 --- a/crates/utils/src/lib.rs +++ b/crates/utils/src/lib.rs @@ -23,7 +23,7 @@ pub fn debug(f: impl Fn(&mut fmt::Formatter) -> fmt::Result) -> impl fmt::Debug /// A hint that this branch is unlikely to be called. #[cold] #[inline(always)] -fn cold() {} +pub fn cold() {} /// A hint that `b` is likely to be true. See `core::intrinsics::likely`. #[inline(always)] @@ -130,3 +130,15 @@ macro_rules! impl_FromEndianBytes { } impl_FromEndianBytes!(i8, i16, i32, i64, isize, u8, u16, u32, u64, usize); + +/// Runs the body block the first time it is encountered. +#[macro_export] +macro_rules! first_time { + ($($stmt:stmt);*) => {{ + use core::cell::LazyCell; + static LAZY_CELL = LazyCell::new(|| { + $($stmt);* + }); + let _: &() = core::cell::LazyCell::force(&LAZY_CELL); + }}; +} |