Wrap getrandom::Error in uuid::Error for Uuid::new_v4 #502
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm submitting a(n) refactor
Description
Resolves the TODO on
Uuid::new_v4
by wrapping thegetrandom::Error
inuuid::Error
.HOWEVER: I don't know if this is a good idea. There's nothing directly wrong with using
Result<_, getrandom::Error>
here, if we're comfortable saying thatnew_v4
is usinggetrandom
to get random bytes from the OS. Wrapping it inuuid::Error
requires removing theHash
impl fromuuid::Error
, and on top of this,getrandom::Error
only implements the stdError
trait if thegetrandom/std
feature is activated. However, there is no (current) way to activate the feature only when bothv4
andstd
features ofuuid
are activated, so we're stuck either requiringv4
to implystd
or to not provide thegetrandom
error as our error'ssource()
. Additionally, since randomness is highly reliable, this is very unlikely to fail, and the only real valid response is to halt the program. We previously just panicked if rand'sthread_rng
was not available, which is (roughly) equivalent togetrandom()
failing. Maintaining this behavior is no worse than static quo, easier to use, sidesteps the features issue, and avoids the breaking change. Users who absolutely need to recover in the face of errors can always construct the random bytes themselves and/or just check thatgetrandom()
doesn't fail.Related Issue(s)
#475, as this is a breaking TODO on the API being requested to publish.
Closes #503: alternate (personally, preferred) approach to the same TODO