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

Un-breaking-change Uuid::new_v4 #503

Merged
merged 1 commit into from
Dec 21, 2020
Merged

Un-breaking-change Uuid::new_v4 #503

merged 1 commit into from
Dec 21, 2020

Conversation

CAD97
Copy link
Contributor

@CAD97 CAD97 commented Dec 21, 2020

I'm submitting a(n) refactor

Description

#447 changed from using rand::thread_rng to using getrandom in Uuid::new_v4. This also changed the return type from Uuid to Result<Uuid, getrandom::Error>. This PR reverts the signature to the simpler new_v4() -> Uuid.

Motivation

This signature is much simpler to use, and avoids a breaking change. getrandom is highly unlikely to fail, and previously we used thread_rng here, which also panics if it fails to initialize from the OS entropy source. If getrandom fails, it is highly unlikely that any program creating v4 UUIDs has any reasonable recovery other than to abort, as the system is in a broken state.

If users absolutely need to recover in this situation, they can call getrandom first themselves to make sure that their system is working, or generate the bytes themselves and create the UUID from those bytes.

Additionally, actually wrapping getrandom::Error in uuid::Error comes with its own fun set of problems, described in #502.

Tests

N/A

Related Issue(s)

#475: this undoes the breaking change to Uuid::new_v4, thus making the requested publish a patch update

Closes #502: alternate approach to the same TODO

@KodrAus
Copy link
Member

KodrAus commented Dec 21, 2020

Thanks @CAD97! It looks like we haven't published a release with the dependency on getrandom. I think treating it as infallible like you're doing here is the best approach.

I'm not sure what state our main branch is at the moment so I've also created a 0.8.x branch off 0.8.1 to backport this to.

@KodrAus
Copy link
Member

KodrAus commented Dec 21, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Dec 21, 2020

Build succeeded:

@bors bors bot merged commit 97e6bf5 into uuid-rs:master Dec 21, 2020
@CAD97 CAD97 deleted the unbreaking branch December 21, 2020 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants