Skip to content

Commit

Permalink
Use getrandom crate for uuid
Browse files Browse the repository at this point in the history
Reduces the number of dependencies.
  • Loading branch information
ammgws committed Jan 19, 2020
1 parent 257b0e5 commit 6d453a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ status = "actively-developed"
[badges.travis-ci]
repository = "uuid-rs/uuid"

[dependencies.getrandom]
optional = true
version = "0.1"

[dependencies.md5]
optional = true
version = "0.7"
Expand Down Expand Up @@ -95,7 +99,7 @@ std = []
stdweb = [ "rand/stdweb" ]
v1 = []
v3 = ["md5"]
v4 = ["rand"]
v4 = ["getrandom"]
v5 = ["sha1"]
wasm-bindgen = ["rand/wasm-bindgen"]

Expand Down
7 changes: 1 addition & 6 deletions src/v4.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::prelude::*;
use rand;

impl Uuid {
/// Creates a random UUID.
Expand All @@ -23,12 +22,8 @@ impl Uuid {
///
/// [`rand`]: https://crates.io/crates/rand
pub fn new_v4() -> Self {
use rand::RngCore;

let mut rng = rand::thread_rng();
let mut bytes = [0; 16];

rng.fill_bytes(&mut bytes);
getrandom::getrandom(&mut bytes).expect("RNG failure!");

Builder::from_bytes(bytes)
.set_variant(Variant::RFC4122)
Expand Down

0 comments on commit 6d453a0

Please sign in to comment.