likely_stable

Crates.iolikely_stable
lib.rslikely_stable
version
sourcesrc
created_at2021-03-09 12:10:04.852802
updated_at2024-12-11 22:59:26.418539
descriptionlikely and unlikely compiler hints in stable rust
homepage
repositoryhttps://gitlab.com/okannen/likely
max_upload_size
id366278
Cargo.toml error:TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Olivier (Kannen)

documentation

README

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"
Commit count: 8

cargo fmt