From 16e0487833cc5170f6b20f988fde24a66f4f9369 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Sat, 7 Aug 2021 19:44:23 +0530 Subject: [PATCH] generate random ids in new --- Cargo.toml | 1 + src/rfc8620.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fe03dd7..8fdea7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/src/rfc8620.rs b/src/rfc8620.rs index f59a017..2c836b3 100644 --- a/src/rfc8620.rs +++ b/src/rfc8620.rs @@ -108,9 +108,10 @@ impl core::fmt::Display for Id { } impl Id { - 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 Id { } } +impl Id { + pub fn new() -> Self { + Self::new_with_prefix("A") + } +} + #[derive(Deserialize, Serialize, Debug)] #[serde(transparent)] pub struct State {