Created
February 21, 2014 22:22
-
-
Save chuckremes/9144857 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
struct Helper { | |
field1: u64 | |
} | |
impl Helper { | |
fn new (foo: u64) -> Helper { | |
Helper { field1: foo } | |
} | |
fn bit_set (&self, bit: u64) -> bool { | |
(self.field1 & bit) == bit | |
} | |
fn empty (&self) -> bool { | |
!self.bit_set(1) | |
} | |
fn set_a_bit (&self, bit: u64) { | |
self.field1 |= bit; | |
} | |
} | |
fn main () { | |
let mut helpera = Helper::new(0); | |
if helpera.empty() { | |
helpera.set_a_bit(2); | |
} | |
} |
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
cremes$ rustc foo2.rs | |
foo2.rs:19:3: 19:14 error: cannot assign to immutable field | |
foo2.rs:19 self.field1 |= bit; | |
^~~~~~~~~~~ | |
error: aborting due to previous error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment