[][src]Crate bit_fiddler

Crate for common bit operations. Mainly for setting, toggling, unsetting and checking bits.

These operations are provided by macros which accept multiple patterns to allow easy bit fiddling. These include operations on a single bit, range of bits, etc. See macro docs for more details.

Macros in this crate don't do overflow/underflow checks. If invalid args are supplied, behaviour depends on the underlying operators and may panic.

Example

use bit_fiddler::set;

let mut bitmap = 0b_0000_0000;
set!(in bitmap, u8, [3..6]);
assert_eq!(bitmap, 0b_0011_1000);

Macros

is_set

Macro for checking if single, multiple or range of bits are set. It accepts multiple patterns for different use cases. It doesn't do any overflow or underflow checks. Behaviour on passing invalid args is undefined.

mask

Macro for getting a bit mask over the given range.

max_bits

For getting total bit count by type or identifier.

set

Macro for setting single, multiple or range of bits. It accepts multiple patterns for different use cases. It doesn't do any overflow or underflow checks. Behaviour on passing invalid args is undefined.

toggle

Macro for toggling single, multiple or range of bits. It accepts multiple patterns for different use cases. It doesn't do any overflow or underflow checks. Behaviour on passing invalid args is undefined.

unset

Macro for usetting single, multiple or range of bits. It accepts multiple patterns for different use cases. It doesn't do any overflow or underflow checks. Behaviour on passing invalid args is undefined.