from_rng_bytes added #172
No reviewers
Labels
No labels
breaking
bug
dependencies
good first issue
help wanted
unstable
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-uuid-rs/uuid!172
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/from-rng"
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?
I'm submitting a ...
Description
As discussed in the issue, this method is a solution to avoid making
randa public dependencyMotivation
To avoid making
randpublic dependencyTests
none, test added
Related Issue(s)
#170
@ -1807,0 +1828,4 @@fn test_from_random_bytes() {let b = [0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6,0xd7, 0xd8,Add space before
{, rustfmt is complaining@ -685,6 +684,33 @@ impl Uuid {Uuid { bytes: b }}We also need to call
set_variantandset_versionhere since the random bytes probably won't have the right values:🚲🏚: I think I also agree with @nox's suggestion of using
from_random_bytesinstead offrom_rng_bytes, since they're not really random number generator bytes, they're just random bytes.Neither
from_rng_bytesnorfrom_random_bytesconvey that we are building av4UUID, and those names are inconsistent withUuid::new_v4.Hmm, I think
Uuid::from_random_bytes(b)conveys that at least as well asrng.gen::<Uuid>()did.This PR should include a patch to
Uuid::new_v4to make it call the new method we are introducing.@ -685,6 +684,33 @@ impl Uuid {Uuid { bytes: b }}There is no reason to feature-gate the method at all.
@ -685,6 +684,33 @@ impl Uuid {Uuid { bytes: b }}We are only generating v4 uuids from this. So why have it on other features?
@ -685,6 +684,33 @@ impl Uuid {Uuid { bytes: b }}Because there is no reason to have to bring in
randif one does not need it. For example in Servo we won't usenew_v4at all (and thus therandinuuid) because we need a better RNG.@ -685,6 +684,33 @@ impl Uuid {Uuid { bytes: b }}ok Cool.
Thanks @Dylan-DPC! Just a few nitpicks.
@ -685,6 +684,33 @@ impl Uuid {Uuid { bytes: b }This wil need to be rebased now since
copy_memoryis now gone.Probably don't need to reference GitHub issues in the docs prose.
I still think we should add an example that's a little more motivating for people using this function, I don't think the value of the bytes we pass in, nor the assertion, should be visible in the remdered docs.
I just copied it from the examples given for the other functions. Will change it accordingly.
Edit: It is common to display the assertion in rust examples. I have seen it in other crates as well and we are doing it for the other examples too.
@ -685,6 +684,33 @@ impl Uuid {Uuid { bytes: b }sure. Since we have so many confusing functions to generate a UUID wanted to leave a note on why do we need this one 😄 will remove it
@KodrAus any further nits? Else can you approve?
@ -685,6 +684,33 @@ impl Uuid {Uuid { bytes: b }We don't need to create a new empty slice here and copy
binto it, we could just create aUuid { bytes: b }.Thanks @Dylan-DPC! Looks good to me!
bors: r+
bors: r+
Build succeeded