summaryrefslogtreecommitdiffstats
path: root/atuin-common
diff options
context:
space:
mode:
authorConrad Ludgate <conradludgate@gmail.com>2023-12-16 19:21:04 +0000
committerGitHub <noreply@github.com>2023-12-16 19:21:04 +0000
commit7aeea1c050a6584507fa4cfc2239fd9289566aa9 (patch)
tree567932a6081425dd2ccff66d5458d18f93c060f2 /atuin-common
parentec131c7c961ad165f4287aa6daabfdf9ae104697 (diff)
chore(deps): uuidv7 stable (#1451)
Diffstat (limited to 'atuin-common')
-rw-r--r--atuin-common/src/utils.rs30
1 files changed, 1 insertions, 29 deletions
diff --git a/atuin-common/src/utils.rs b/atuin-common/src/utils.rs
index 8358802a..59050b96 100644
--- a/atuin-common/src/utils.rs
+++ b/atuin-common/src/utils.rs
@@ -12,36 +12,8 @@ pub fn random_bytes<const N: usize>() -> [u8; N] {
ret
}
-// basically just ripped from the uuid crate. they have it as unstable, but we can use it fine.
-const fn encode_unix_timestamp_millis(millis: u64, random_bytes: &[u8; 10]) -> Uuid {
- let millis_high = ((millis >> 16) & 0xFFFF_FFFF) as u32;
- let millis_low = (millis & 0xFFFF) as u16;
-
- let random_and_version =
- (random_bytes[0] as u16 | ((random_bytes[1] as u16) << 8) & 0x0FFF) | (0x7 << 12);
-
- let mut d4 = [0; 8];
-
- d4[0] = (random_bytes[2] & 0x3F) | 0x80;
- d4[1] = random_bytes[3];
- d4[2] = random_bytes[4];
- d4[3] = random_bytes[5];
- d4[4] = random_bytes[6];
- d4[5] = random_bytes[7];
- d4[6] = random_bytes[8];
- d4[7] = random_bytes[9];
-
- Uuid::from_fields(millis_high, millis_low, random_and_version, &d4)
-}
-
pub fn uuid_v7() -> Uuid {
- let bytes = random_bytes();
- let now: u64 = u64::try_from(
- time::OffsetDateTime::now_utc().unix_timestamp_nanos() / 1_000_000,
- )
- .expect("Either you're in the past (1970) - or your in the far future (2554). Good for you");
-
- encode_unix_timestamp_millis(now, &bytes)
+ Uuid::now_v7()
}
pub fn uuid_v4() -> String {