Skip to content

Commit

Permalink
use base64 general_purpose
Browse files Browse the repository at this point in the history
  • Loading branch information
kinosang committed Nov 23, 2023
1 parent 3a395c8 commit a00bd53
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fastid"
version = "0.3.0"
version = "0.3.1"
authors = ["Chino Chang <chino@joymoe.com>"]
edition = "2021"

Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ impl FastId {

#[cfg(feature = "base64")]
pub fn to_base64(&self) -> String {
use base64::{engine::general_purpose::STANDARD, Engine as _};

let bytes = u64::to_le_bytes(self.as_u64());
format!("{:0>12}", base64::encode(bytes))
format!("{:0>12}", STANDARD.encode(bytes))
}
}

Expand Down Expand Up @@ -178,8 +180,7 @@ impl FastIdWorker {
let node_id = u64::to_be_bytes(self.machine_id & 0xFFFF_FFFF_FFFF);
d4[2..].copy_from_slice(&node_id[2..]);

let guid = uuid::Uuid::from_fields(time_low, time_mid, time_high_and_version, &d4)
.unwrap();
let guid = uuid::Uuid::from_fields(time_low, time_mid, time_high_and_version, &d4);

return FastId(id, guid);
}
Expand Down

0 comments on commit a00bd53

Please sign in to comment.