#branch #hint #likely #intrinsics

no-std branch_hints

Crate that provides likely and unlikely branch hint functions in stable Rust

5 unstable releases

0.4.0 Feb 20, 2024
0.3.1 Oct 22, 2023
0.2.1 Feb 3, 2023
0.2.0 Dec 23, 2022
0.1.2 Dec 22, 2022

#113 in No standard library

28 downloads per month

MIT license

5KB

branch_hints

This crate provides the functions likely and unlikely that work as compiler hints for branching.

These functions enable constructions like

if likely(condition) {
    // main code
} else {
    // error handling code
}

and they should be optimized away by the compiler.

Credit

The functions are taken directly from the hashbrown crate and this crate simply exposes them, all credit belongs to the hashbrown authors.

Note

This is a very minimal crate. If you want more comprehensive functionality, take a look at the likely_stable crate.


lib.rs:

This crate provides likely and unlikely functions that work as compiler hints for branching in stable rust. They are taken directly from the hashbrown crate, all credit belongs to them. These functions enable constructions like

if likely(condition) {
    // main code
} else {
    // error handling code
}

and they should be optimized away by the compiler.

Notes

This is a very minimal crate. If you want more comprehensive functionality, take a look at the likely_stable crate.

No runtime deps