Skip to content

Instantly share code, notes, and snippets.

@tilpner
Created January 1, 2015 19:40
Show Gist options
  • Save tilpner/cece8b05d3caec0d603e to your computer and use it in GitHub Desktop.
Save tilpner/cece8b05d3caec0d603e to your computer and use it in GitHub Desktop.
A generic way to set bits. Yeah, you don't have to like it...
/// Never really tested this...
#[inline(always)]
fn set_bit<T: One + BitOr<T, T> + BitAnd<T, T> + Shl<T, T> + Not<T>>(val: T, bit: T, on: bool) -> T {
if on { val | one::<T>() << bit } else { val & !(one::<T>() << bit) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment