diff --git a/src/v4.rs b/src/v4.rs index 45d2003e5..a29751c29 100644 --- a/src/v4.rs +++ b/src/v4.rs @@ -4,10 +4,10 @@ impl Uuid { /// Creates a random UUID. /// /// This uses the [`getrandom`] crate to utilise the operating system's RNG - /// as the source of random numbers. If you'd like to use a custom generator, - /// don't use this method: generate random bytes using your custom generator - /// and pass them to the [`uuid::Builder::from_bytes`][from_bytes] function - /// instead. + /// as the source of random numbers. If you'd like to use a custom + /// generator, don't use this method: generate random bytes using your + /// custom generator and pass them to the + /// [`uuid::Builder::from_bytes`][from_bytes] function instead. /// /// Note that usage of this method requires the `v4` feature of this crate /// to be enabled. @@ -24,16 +24,17 @@ impl Uuid { /// /// [`getrandom`]: https://crates.io/crates/getrandom /// [from_bytes]: struct.Builder.html#method.from_bytes - // TODO: change signature to support uuid's Error. - pub fn new_v4() -> Result { + pub fn new_v4() -> Uuid { let mut bytes = [0u8; 16]; - getrandom::getrandom(&mut bytes)?; + getrandom::getrandom(&mut bytes).unwrap_or_else(|err| { + // NB: getrandom::Error has no source; this is adequate display + panic!("could not retreive random bytes for uuid: {}", err) + }); - let uuid = crate::Builder::from_bytes(bytes) + crate::Builder::from_bytes(bytes) .set_variant(Variant::RFC4122) .set_version(Version::Random) - .build(); - Ok(uuid) + .build() } } @@ -43,7 +44,7 @@ mod tests { #[test] fn test_new() { - let uuid = Uuid::new_v4().unwrap(); + let uuid = Uuid::new_v4(); assert_eq!(uuid.get_version(), Some(Version::Random)); assert_eq!(uuid.get_variant(), Some(Variant::RFC4122)); @@ -51,7 +52,7 @@ mod tests { #[test] fn test_get_version() { - let uuid = Uuid::new_v4().unwrap(); + let uuid = Uuid::new_v4(); assert_eq!(uuid.get_version(), Some(Version::Random)); assert_eq!(uuid.get_version_num(), 4)