Created
June 20, 2016 21:05
-
-
Save mbrubeck/22ec186759f36af65d324780248e5bd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait BitStorage { | |
fn set(&mut self, index: usize, value: bool); | |
} | |
impl BitStorage for u8 { | |
fn set(&mut self, index: usize, value: bool) { | |
*self |= (value as u8) << index | |
} | |
} | |
fn main() { | |
let mut x = 0u8; | |
x.set(4, true); | |
println!("{:08b}", x); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment