Hi. I want my struct to contain a unique i32 in a private field. I'll use them as ids. The code below requires unsafe block:
mod MyTypes {
static mut COUNTER: i32 = 0;
pub struct MyStruct {
id: i32,
}
impl MyStruct {
fn new() -> Self {
COUNTER += 1;
Self { id: COUNTER }
}
}
}
Now of course, I can create unix timestamps in the constructor method and use them as ids but are there any other methods?