likely_polyfill 1.0.0

cold_path, likely, and unlikely for non-nightly Rust
Documentation
// The code here has been copied from
// https://github.com/rust-lang/rust/blob/d25910eaeb3eab25d3bbf9b9815e6d215c202d1f/library/core/src/intrinsics/mod.rs
//
// https://github.com/rust-lang/rust/blob/d25910eaeb3eab25d3bbf9b9815e6d215c202d1f/REUSE.toml indicates
// SPDX-FileCopyrightText = "The Rust Project Developers (see https://thanks.rust-lang.org)"
// SPDX-License-Identifier = "MIT or Apache-2.0"

#![no_std]

//! As a workaround to their [stabilization in the standard library](https://github.com/rust-lang/rust/issues/136873) remaining perma-open,
//! this crate provides the `cold_path`, `likely`, and `unlikely` hints
//! built on the `#[cold]` annotation as copied and pasted from the standard library source.

/// Hints to the compiler that current code path is cold.
#[inline(always)]
#[cold]
pub const fn cold_path() {}

/// Hints to the compiler that branch condition is likely to be true.
/// Returns the value passed to it.
#[inline(always)]
pub const fn likely(b: bool) -> bool {
    if b {
        true
    } else {
        cold_path();
        false
    }
}

/// Hints to the compiler that branch condition is likely to be false.
/// Returns the value passed to it.
#[inline(always)]
pub const fn unlikely(b: bool) -> bool {
    if b {
        cold_path();
        true
    } else {
        false
    }
}