2 unstable releases

0.2.0 Dec 8, 2020
0.1.0 Jul 30, 2018

#529 in Hardware support

Download history 100/week @ 2023-11-20 71/week @ 2023-11-27 38/week @ 2023-12-04 78/week @ 2023-12-11 79/week @ 2023-12-18 65/week @ 2023-12-25 31/week @ 2024-01-01 84/week @ 2024-01-08 74/week @ 2024-01-15 33/week @ 2024-01-22 41/week @ 2024-01-29 67/week @ 2024-02-05 88/week @ 2024-02-12 75/week @ 2024-02-19 141/week @ 2024-02-26 88/week @ 2024-03-04

393 downloads per month
Used in 31 crates (27 directly)

MIT license

8KB

likely

likely is a rust crate used to provide macro wrappers around the intrinsics ::std::intrinsic::likely and ::std::intrinsic::unlikely, which themselves are hints to the CPU's branch predictor.

These hints should only be used when the vast majority of cases would satisfy them. A typicaly example might be a highly unusual error condition, or an extreme value or outlier in a range. Another common scenario is dealing with return codes from common libc functions, many of which are highly unlikely to occur (eg EINVAL for many such functions).

Note that using these macro wrappers requires compiling with nightly.

Using It.

Firstly, Include it

To include it, add the following to your Cargo.toml:-

[dependencies]
likely = "^0.1"

In your crate's lib.rs, add:-

`#![feature(core_intrinsics)]`

...

#[macro_use] extern crate likely;

Secondly, use it with if statements

fn example(age: u8)
{
	if likely!(age <= 70)
	{
		println!("Not yet entitled to this welfare benefit")
	}
	else if unlikely!(age == 99)
	{
		println!("You are entitled to a birthday card from the Queen for your next birthday")
	}
}

Licensing

The license for this project is MIT.

No runtime deps