I would like to give my object a unique ID (to be able to compare them). I figured to do something along these lines:
pub struct Player {
id: i32,
score: usize,
}
impl Player {
fn new() -> Player {
let mut player = Player {};
player.id = &player as *const i32;
player
}
}
I run into the problem that I need to set the variables when defining the Player
, but there is no memory address at that point.
I could make the id
mutable, but there is no need to change the variable after initialisation.
How can I do something like this?