Support counters in v7 UUIDs #755
No reviewers
Labels
No labels
breaking
bug
dependencies
good first issue
help wanted
unstable
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-uuid-rs/uuid!755
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/v7-counter"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
For #717
This PR sketches out a solution to make the v7 support respect the input counter, while retaining existing semantics around filling with random data. It requires a bit of fudgery to keep compatibility with existing APIs, but I think the overall solution works out ok. I need to actually fill it all in fully and then explore ways to better integrate the existing
TimestampAPI, which may involve deprecating bits.The gist of it is to add a
usable_bitsmethod toClockSequence, so it can tell how many bits a given counter occupies. The UUID constructor can then do appropriate shifts and fill the rest with random bytes. That way a caller creating a v7 UUID can decide how many bits to dedicate to sequencing and how many to randomness.As part of this PR I'm expecting to find some solution to re-seeding sequences, which will probably remain an implementation detail of the given
ClockSequence.@ -358,0 +475,4 @@/// to adjust the timestamp on overflow.#[derive(Debug)]pub struct Context {count: Atomic<u16>,We need to add another implementation here with a 42bit counter that's intended to be used by v7 UUIDs.
These examples should use
Timestamp::from_unix_widewith a 42bit counter to steer users wanting counters in the right direction.I've got a counter implemented, but looks like performance here could use some improvement compared to
uuid7:Ok, I think that's better now:
I need to add some tests for the new v7 context, and make sure we're shifting it around the variant field correctly.