From 210e7c438b6ce26271ab95683e19dfd2fe3e8b31 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Sun, 29 Jun 2025 11:22:50 +0300 Subject: [PATCH] utils --- src/lib.rs | 1 + src/utils.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/utils.rs diff --git a/src/lib.rs b/src/lib.rs index 9c39b6e..00d1928 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,6 +27,7 @@ pub use trait_set::trait_set; pub mod array; pub mod error; +pub mod utils; pub mod fut; pub mod time; diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..4a6df54 --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,21 @@ +//! # Uncategorized useful functionality + +/// Hint that this branch is cold. +#[inline(always)] +pub const fn cold(v: T) -> T { + v +} + +/// Indicate that this value is unlikely to be true. Hint to +/// the compiler. +#[inline(always)] +pub const fn unlikely(v: bool) -> bool { + if v { cold(true) } else { false } +} + +/// Indicate that this value is likely to be true. Hint to +/// the compiler. +#[inline(always)] +pub const fn likely(v: bool) -> bool { + if v { true } else { cold(false) } +}