1 unstable release

0.1.2 Mar 9, 2021
0.1.1 Mar 9, 2021
0.1.0 Mar 9, 2021

#410 in No standard library

Download history 1148/week @ 2024-03-17 1848/week @ 2024-03-24 1722/week @ 2024-03-31 1758/week @ 2024-04-07 1898/week @ 2024-04-14 2161/week @ 2024-04-21 1553/week @ 2024-04-28 2580/week @ 2024-05-05 2176/week @ 2024-05-12 2508/week @ 2024-05-19 2407/week @ 2024-05-26 2506/week @ 2024-06-02 1845/week @ 2024-06-09 2013/week @ 2024-06-16 2237/week @ 2024-06-23 838/week @ 2024-06-30

7,137 downloads per month
Used in 5 crates (4 directly)

MIT/Apache

29KB
675 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"

Dependencies

~200KB