summaryrefslogblamecommitdiff
path: root/meap/meap-code/ch2/ch2-define-type.rs
blob: 45dbcdaf590418bb567f28aec5f6c894e6f5a1d6 (plain) (tree)





















                                     
struct Counter {
  value: u64, // <1>
}

impl Counter {
  fn new() -> Self { // <2> <3>
    Counter { value: 0 } // <4> <5>
  }

  fn incr(&mut self) { // <6>
    self.value += 1;
  }
}

fn main() {
   let mut counter = Counter::new();

   counter.incr();
   counter.incr();

   println!("{}", counter.value);
}