Browse Source

generate random ids in new

Ujjwal Sharma 4 months ago
parent
commit
16e0487833
No known key found for this signature in database GPG Key ID: 460B292812C67D9F
  1. 1
      Cargo.toml
  2. 11
      src/rfc8620.rs

1
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"] }

11
src/rfc8620.rs

@ -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> {

Loading…
Cancel
Save