This crates brings likely and unlikely branch prediction hints to stable rust ``` use likely_stable::{likely,unlikely}; use rand::random;
if likely(random::
It also provides [macro@iflikely] and [macro@ifunlikely] for branch prediction
for if let
statements.
```
use likelystable::iflikely;
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.maporelse_likely( || println!("unlikely"), |v| println!("likely {}",v)); ```
Add this to your Cargo.toml
:
toml
[dependencies]
likely_stable = "0.1"