dylanhart / ulid-rs

This is a Rust implementation of the ulid project
https://crates.io/crates/ulid
MIT License
389 stars 37 forks source link

UUIDv7 conversions #49

Closed dylanhart closed 2 years ago

dylanhart commented 2 years ago

UUIDv7 conversions that keep the timestamp and random value would be nice to have.

oylenshpeegul commented 2 years ago

How would this work? ULIDs have 80 bits of randomness, but UUIDv7s have only 74 (4 bits are fixed for version and 2 bits are fixed for variant).

I think the conversions done now work for converting a UUIDv7 into a ULID. The 48 bit timestamp is preserved and you can pretend that you have 80 bits of randomness if you want.

But wouldn't converting a ULID into a UUIDv7 require overwriting six of the randomness bits with the six fixed bits demanded? So you can't really keep the (entire) random value, right?