我想给我的对象一个唯一的ID(以便进行比较)。我想按照这些思路做些事情:
pub struct Player {
id: i32,
score: usize,
}
impl Player {
fn new() -> Player {
let mut player = Player {};
player.id = &player as *const i32;
player
}
}
遇到一个问题,我在定义Player
时需要设置变量,但是此时没有内存地址。
我可以使id
可变,但是初始化之后无需更改变量。
我该怎么做?