Skip to content
Quiz · Structs · lesson 4 of 8

Quiz — a &mut self method

What happens when this program is built and run?

Rust
struct Counter {
    n: u32,
}
impl Counter {
    fn inc(&mut self) {
        self.n += 1;
    }
}
fn main() {
    let c = Counter { n: 0 };
    c.inc();
}