2 releases

0.1.3 Dec 11, 2024
0.1.2 Mar 9, 2021
0.1.1 Mar 9, 2021
0.1.0 Mar 9, 2021

#136 in Hardware support

Download history 5399/week @ 2024-08-30 5819/week @ 2024-09-06 5740/week @ 2024-09-13 5559/week @ 2024-09-20 5122/week @ 2024-09-27 5411/week @ 2024-10-04 5861/week @ 2024-10-11 6653/week @ 2024-10-18 5715/week @ 2024-10-25 5595/week @ 2024-11-01 5135/week @ 2024-11-08 5858/week @ 2024-11-15 2268/week @ 2024-11-22 4240/week @ 2024-11-29 4669/week @ 2024-12-06 3909/week @ 2024-12-13

16,144 downloads per month
Used in 6 crates (4 directly)

MIT/Apache

31KB
674 lines

LICENSE LICENSE Documentation Crates.io Version

This crates brings likely and unlikely branch prediction hints to stable rust

use likely_stable::{likely,unlikely};
use rand::random;

if likely(random::<i32>() > 10) {
    println!("likely!")
} else {
    println!("unlikely!")
}

It also provides if_likely and if_unlikely for branch prediction for if let statements.

use likely_stable::if_likely;
use rand::random;

let v = Some(random()).filter(|v:&i32| *v > 10);

if_likely!{let Some(v) = v => {
    println!("likely!")
} else {
    println!("unlikely!")
}};

Moreover traits LikelyBool, LikelyOption and LikelyResult provides likely and unlikely versions of the methods commonly used for types bool, Option and Result

use likely_stable::LikelyOption;
use rand::random;

let v = Some(random()).filter(|v:&i32| *v > 10);

v.map_or_else_likely(
    || println!("unlikely"),
    |v| println!("likely {}",v));

Usage

Add this to your Cargo.toml:

[dependencies]
likely_stable = "0.1"

No runtime deps

~9KB