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 17, 2020
1 parent 257b0e5 commit 4928623
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ homepage = "https://github.com/uuid-rs/uuid"
name = "uuid"
readme = "README.md"
repository = "https://github.com/uuid-rs/uuid"
version = "0.8.1" # remember to update html_root_url in lib.rs
version = "0.8.2" # remember to update html_root_url in lib.rs

[package.metadata.docs.rs]
features = [ "guid", "serde", "slog", "v1", "v3", "v4", "v5" ]
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
#![doc(
html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "https://www.rust-lang.org/favicon.ico",
html_root_url = "https://docs.rs/uuid/0.8.1"
html_root_url = "https://docs.rs/uuid/0.8.2"
)]

#[cfg(any(feature = "std", test))]
Expand Down
8 changes: 2 additions & 6 deletions src/v4.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::prelude::*;
use rand;
use getrandom::getrandom;

impl Uuid {
/// Creates a random UUID.
Expand All @@ -23,12 +23,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(&mut bytes).expect("RNG failure!");

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

0 comments on commit 4928623

Please sign in to comment.