Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infallible Generator generation #71

Open
Ekleog opened this issue Jan 29, 2024 · 2 comments · May be fixed by #75
Open

Infallible Generator generation #71

Ekleog opened this issue Jan 29, 2024 · 2 comments · May be fixed by #75

Comments

@Ekleog
Copy link

Ekleog commented Jan 29, 2024

Hey!

I see that all the methods in Generator are currently infallible. It certainly makes sense, in order to be sure that the timestamp part of the ULID stays technically correct.

However, I'd argue that most of the time the system clock is not set to millisecond accuracy, and fewer than 2**80 ULIDs are generated per second.

As such, I'd like to introduce an infallible Generator::generate_overflowing() (or similar name) method, that'd just make +1 to the u128 in case the randomly-generated ULID was before the last one output, and still allow overflow in the time bits.

Would you be interested in such a PR?

@dylanhart
Copy link
Owner

Yes, this is a very good improvement.

The only real case where an overflow would occur would be getting exceptionally lucky on the random roll.

Ulid::increment_overflowing could also be added as a matching API.

@Ekleog
Copy link
Author

Ekleog commented Feb 2, 2024

Cool! I have opened #75 with the implementation :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants