generate random ids in new

Ujjwal Sharma 2021-08-07 19:44:23 +05:30
parent e90e83c310
commit 16e0487833
Failed to generate hash of commit
2 changed files with 10 additions and 2 deletions

View File

@ -14,3 +14,4 @@ serde = { version = "1.0.71", features = ["rc", ] }
serde_derive = "1.0.71"
serde_json = { version = "1.0", features = ["raw_value",] }
smallvec = { version = "^1.5.0", features = ["serde", ] }
uuid = { version = "0.8", features = ["serde", "v4"] }

View File

@ -108,9 +108,10 @@ impl<OBJ> core::fmt::Display for Id<OBJ> {
}
impl<OBJ> Id<OBJ> {
pub fn new() -> Self {
fn new_with_prefix(prefix: &str) -> Self {
let id = uuid::Uuid::new_v4().to_string();
Self {
inner: String::new(),
inner: String::from(prefix) + &id,
_ph: PhantomData,
}
}
@ -128,6 +129,12 @@ impl<OBJ> Id<OBJ> {
}
}
impl Id<Account> {
pub fn new() -> Self {
Self::new_with_prefix("A")
}
}
#[derive(Deserialize, Serialize, Debug)]
#[serde(transparent)]
pub struct State<OBJ> {