struct Counter { count: u32, } impl Counter { fn new() -> Self { Counter { count: 0 } } fn increment(&mut self) { // TODO: self.count += 1 } fn get(&self) -> u32 { self.count } } fn main() { let mut c = Counter::new(); c.increment(); c.increment(); println!("{}", c.get()); }
Output
Click Run to execute, or Check to validate.
Ask questions or share tips about this tutorial
Sign in to join the discussion