22 lines
414 B
Rust
22 lines
414 B
Rust
|
use serde::{Serialize, Deserialize};
|
||
|
use rand::{thread_rng, Rng};
|
||
|
|
||
|
/// ID
|
||
|
#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq, Hash)]
|
||
|
pub struct Id(pub u64);
|
||
|
impl Id {
|
||
|
pub fn to_string(&self) -> String {
|
||
|
format!("{:x}", self.0)
|
||
|
}
|
||
|
}
|
||
|
impl Into<String> for Id {
|
||
|
fn into(self) -> String {
|
||
|
format!("{:x}", self.0)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn generate_id() -> Id {
|
||
|
Id(thread_rng().gen())
|
||
|
}
|
||
|
|