Function rumio::set_bits[][src]

pub fn set_bits<I: Int>(num: I, (start, end): (usize, usize), bits: I) -> I

Sets the range (inclusive) of bits, given by the (start, end) tuple, to the given bits value.

Note that this mehtod does not validate anything, for example the range is out of bounds. It will fail silently and may cause "undefined behaviour" if the wrong arguments are passed.

Example


let x = 0u32;

let x = set_bits(x, (0, 1), 0b11);
assert_eq!(x, 0b11);

let x = set_bits(x, (1, 3), 0b010);
assert_eq!(x, 0b0101);

let x = set_bits(x, (0, 4), 0b11001);
assert_eq!(x, 0b11001);