I want to create a mutable structure on the stack and change it from helper functions.
#[derive(Debug)] struct Game { score: u32, } fn addPoint(game: &mut Game) { game.score += 1; } fn main() { let mut game = Game { score: 0 }; println!("Initial game: {:?}", game);
Trying to compile this gives:
error[E0308]: mismatched types --> src/main.rs:19:14 | 19 | addPoint(&game); | ^^^^^ types differ in mutability | = note: expected type '&mut Game' found type '&Game'
What am I doing wrong?
source share