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

#142 in Hardware support

Download history 4978/week @ 2024-09-26 5692/week @ 2024-10-03 5701/week @ 2024-10-10 6428/week @ 2024-10-17 6117/week @ 2024-10-24 5457/week @ 2024-10-31 5161/week @ 2024-11-07 5907/week @ 2024-11-14 3039/week @ 2024-11-21 3557/week @ 2024-11-28 4587/week @ 2024-12-05 4946/week @ 2024-12-12 2603/week @ 2024-12-19 892/week @ 2024-12-26 3259/week @ 2025-01-02 4543/week @ 2025-01-09

12,223 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