Skip to content

Instantly share code, notes, and snippets.

@chuckremes
Created February 21, 2014 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuckremes/9144857 to your computer and use it in GitHub Desktop.
Save chuckremes/9144857 to your computer and use it in GitHub Desktop.
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);
}
}
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