From 4b64f47c97c04616732e91107c04689099dc198e Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sat, 17 Mar 2018 21:12:44 +0530 Subject: [PATCH 01/23] from_rng_bytes added --- src/lib.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 4d75fbc95..6ca519a8b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -685,6 +685,33 @@ impl Uuid { Uuid { bytes: b } } + /// Creates a v4 Uuid from rng bytes (ref issue #170) + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// use uuid::Uuid; + /// use uuid::UuidBytes; + /// + /// let bytes:UuidBytes = [70, 235, 208, 238, 14, 109, 67, 201, 185, 13, 204, 195, 90, 145, 63, 62]; + /// + /// let uuid = Uuid::from_rng_bytes(bytes); + /// let uuid = uuid.hyphenated().to_string(); + /// + /// let expected_uuid = String::from("46ebd0ee-0e6d-43c9-b90d-ccc35a913f3e"); + /// + /// assert_eq!(expected_uuid, uuid); + /// ``` + /// + #[allow(dead_code)] + fn from_rng_bytes(b: [u8; 16]) -> Uuid { + let mut uuid = Uuid { bytes: [0; 16] }; + copy_memory(&mut uuid.bytes, &b); + uuid + } + /// Specifies the variant of the UUID structure #[allow(dead_code)] fn set_variant(&mut self, v: UuidVariant) { @@ -1804,6 +1831,19 @@ mod tests { assert_eq!(&b_in, b_out); } + #[test] + fn test_from_rnd_bytes(){ + let b = [ + 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, + 0xd7, 0xd8, + ]; + + let u = Uuid::from_rng_bytes(b); + let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8"; + + assert_eq!(u.simple().to_string(), expected); + } + #[test] fn test_operator_eq() { let u1 = new(); From be08da9be5b1ff756dd4df6cca4492afb897c6a2 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sat, 17 Mar 2018 21:22:23 +0530 Subject: [PATCH 02/23] feature check added --- src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 6ca519a8b..cc434e3de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -705,6 +705,7 @@ impl Uuid { /// assert_eq!(expected_uuid, uuid); /// ``` /// + #[cfg(feature = "v4")] #[allow(dead_code)] fn from_rng_bytes(b: [u8; 16]) -> Uuid { let mut uuid = Uuid { bytes: [0; 16] }; @@ -1832,7 +1833,8 @@ mod tests { } #[test] - fn test_from_rnd_bytes(){ + #[cfg(feature = "v4")] + fn test_from_rng_bytes(){ let b = [ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, From dcb98d9b1c80146e7fc17602e28cf9e23a207c8c Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sat, 17 Mar 2018 21:30:38 +0530 Subject: [PATCH 03/23] method made public --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index cc434e3de..1aceb3f8f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -707,7 +707,7 @@ impl Uuid { /// #[cfg(feature = "v4")] #[allow(dead_code)] - fn from_rng_bytes(b: [u8; 16]) -> Uuid { + pub fn from_rng_bytes(b: [u8; 16]) -> Uuid { let mut uuid = Uuid { bytes: [0; 16] }; copy_memory(&mut uuid.bytes, &b); uuid From 35e340b43ed21ecdca5ec2cc0747aeafed745742 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sat, 17 Mar 2018 23:06:17 +0530 Subject: [PATCH 04/23] allow dead code removed --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 1aceb3f8f..33f5e1fa3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -706,7 +706,6 @@ impl Uuid { /// ``` /// #[cfg(feature = "v4")] - #[allow(dead_code)] pub fn from_rng_bytes(b: [u8; 16]) -> Uuid { let mut uuid = Uuid { bytes: [0; 16] }; copy_memory(&mut uuid.bytes, &b); From 289963e50faed5bdd7f94b83ac444b84f8717f19 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sat, 17 Mar 2018 23:13:41 +0530 Subject: [PATCH 05/23] after running cargo fmt --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 33f5e1fa3..fe1c78e32 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1833,7 +1833,7 @@ mod tests { #[test] #[cfg(feature = "v4")] - fn test_from_rng_bytes(){ + fn test_from_rng_bytes() { let b = [ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, From e9d48bac22ad742b8c90095adaed06b63566b778 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sun, 18 Mar 2018 16:50:11 +0530 Subject: [PATCH 06/23] add set variant & version name changed to from_random_bytes --- src/lib.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fe1c78e32..a916396de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -697,7 +697,7 @@ impl Uuid { /// /// let bytes:UuidBytes = [70, 235, 208, 238, 14, 109, 67, 201, 185, 13, 204, 195, 90, 145, 63, 62]; /// - /// let uuid = Uuid::from_rng_bytes(bytes); + /// let uuid = Uuid::from_random_bytes(bytes); /// let uuid = uuid.hyphenated().to_string(); /// /// let expected_uuid = String::from("46ebd0ee-0e6d-43c9-b90d-ccc35a913f3e"); @@ -706,9 +706,11 @@ impl Uuid { /// ``` /// #[cfg(feature = "v4")] - pub fn from_rng_bytes(b: [u8; 16]) -> Uuid { + pub fn from_random_bytes(b: [u8; 16]) -> Uuid { let mut uuid = Uuid { bytes: [0; 16] }; copy_memory(&mut uuid.bytes, &b); + uuid.set_variant(UuidVariant::RFC4122); + uuid.set_version(UuidVersion::Random); uuid } @@ -1833,13 +1835,13 @@ mod tests { #[test] #[cfg(feature = "v4")] - fn test_from_rng_bytes() { + fn test_from_random_bytes() { let b = [ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, ]; - let u = Uuid::from_rng_bytes(b); + let u = Uuid::from_random_bytes(b); let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8"; assert_eq!(u.simple().to_string(), expected); From bd30f895d7e4e3515458a2240c56e92975514b81 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sun, 18 Mar 2018 17:41:50 +0530 Subject: [PATCH 07/23] feature gate removed --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index a916396de..c48505aee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -705,7 +705,6 @@ impl Uuid { /// assert_eq!(expected_uuid, uuid); /// ``` /// - #[cfg(feature = "v4")] pub fn from_random_bytes(b: [u8; 16]) -> Uuid { let mut uuid = Uuid { bytes: [0; 16] }; copy_memory(&mut uuid.bytes, &b); From 4909a19a4964812e5da856195935d85a26d66fcf Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Mon, 19 Mar 2018 03:50:20 +0530 Subject: [PATCH 08/23] reroute new_v4 to from_random_bytes --- src/lib.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c48505aee..182ea94d3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -507,11 +507,10 @@ impl Uuid { let mut rng = rand::thread_rng(); - let mut uuid = Uuid { bytes: [0; 16] }; - rng.fill_bytes(&mut uuid.bytes); - uuid.set_variant(UuidVariant::RFC4122); - uuid.set_version(UuidVersion::Random); - uuid + let mut bytes = [0; 16]; + rng.fill_bytes(&mut bytes); + + Uuid::from_random_bytes(bytes) } /// Creates a UUID using a name from a namespace, based on the SHA-1 hash. From 3b96ad2a9bd563fbb23025e332ad0573f399cc96 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Mon, 19 Mar 2018 04:06:52 +0530 Subject: [PATCH 09/23] unwanted feature gate removed --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 182ea94d3..2baca0667 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1832,7 +1832,6 @@ mod tests { } #[test] - #[cfg(feature = "v4")] fn test_from_random_bytes() { let b = [ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, From 9c0a85f13e0df0063bdaa875c33e92432055f443 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Mon, 19 Mar 2018 04:14:35 +0530 Subject: [PATCH 10/23] change expected value because variant & version are added --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 2baca0667..6a58a2874 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1839,7 +1839,7 @@ mod tests { ]; let u = Uuid::from_random_bytes(b); - let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8"; + let expected = "a1a2a3a4b1b241c291d2d3d4d5d6d7d8"; assert_eq!(u.simple().to_string(), expected); } From 32c966459a2eec9e44808ad9d2893d7f01e0b924 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sat, 17 Mar 2018 21:12:44 +0530 Subject: [PATCH 11/23] from_rng_bytes added --- src/lib.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index f3a81c540..61d1cd061 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -685,6 +685,33 @@ impl Uuid { Uuid { bytes: b } } + /// Creates a v4 Uuid from rng bytes (ref issue #170) + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// use uuid::Uuid; + /// use uuid::UuidBytes; + /// + /// let bytes:UuidBytes = [70, 235, 208, 238, 14, 109, 67, 201, 185, 13, 204, 195, 90, 145, 63, 62]; + /// + /// let uuid = Uuid::from_rng_bytes(bytes); + /// let uuid = uuid.hyphenated().to_string(); + /// + /// let expected_uuid = String::from("46ebd0ee-0e6d-43c9-b90d-ccc35a913f3e"); + /// + /// assert_eq!(expected_uuid, uuid); + /// ``` + /// + #[allow(dead_code)] + fn from_rng_bytes(b: [u8; 16]) -> Uuid { + let mut uuid = Uuid { bytes: [0; 16] }; + copy_memory(&mut uuid.bytes, &b); + uuid + } + /// Specifies the variant of the UUID structure #[allow(dead_code)] fn set_variant(&mut self, v: UuidVariant) { @@ -1798,6 +1825,19 @@ mod tests { assert_eq!(&b_in, b_out); } + #[test] + fn test_from_rnd_bytes(){ + let b = [ + 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, + 0xd7, 0xd8, + ]; + + let u = Uuid::from_rng_bytes(b); + let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8"; + + assert_eq!(u.simple().to_string(), expected); + } + #[test] fn test_operator_eq() { let u1 = new(); From f3b37e638c4fd8665403c4e84e18498ac7bf3c5e Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sat, 17 Mar 2018 21:22:23 +0530 Subject: [PATCH 12/23] feature check added --- src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 61d1cd061..811769907 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -705,6 +705,7 @@ impl Uuid { /// assert_eq!(expected_uuid, uuid); /// ``` /// + #[cfg(feature = "v4")] #[allow(dead_code)] fn from_rng_bytes(b: [u8; 16]) -> Uuid { let mut uuid = Uuid { bytes: [0; 16] }; @@ -1826,7 +1827,8 @@ mod tests { } #[test] - fn test_from_rnd_bytes(){ + #[cfg(feature = "v4")] + fn test_from_rng_bytes(){ let b = [ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, From 788571127a36db9383cd77f1b5759930de3a222f Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sat, 17 Mar 2018 21:30:38 +0530 Subject: [PATCH 13/23] method made public --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 811769907..e216353ea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -707,7 +707,7 @@ impl Uuid { /// #[cfg(feature = "v4")] #[allow(dead_code)] - fn from_rng_bytes(b: [u8; 16]) -> Uuid { + pub fn from_rng_bytes(b: [u8; 16]) -> Uuid { let mut uuid = Uuid { bytes: [0; 16] }; copy_memory(&mut uuid.bytes, &b); uuid From 6ff8bb9869c03d0be7aea1667ca61eccf12dc329 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sat, 17 Mar 2018 23:06:17 +0530 Subject: [PATCH 14/23] allow dead code removed --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index e216353ea..7e0c7453a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -706,7 +706,6 @@ impl Uuid { /// ``` /// #[cfg(feature = "v4")] - #[allow(dead_code)] pub fn from_rng_bytes(b: [u8; 16]) -> Uuid { let mut uuid = Uuid { bytes: [0; 16] }; copy_memory(&mut uuid.bytes, &b); From e29c21979a9e55b9386e97203e8edf3b822c5d0f Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sat, 17 Mar 2018 23:13:41 +0530 Subject: [PATCH 15/23] after running cargo fmt --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 7e0c7453a..7877fad8a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1827,7 +1827,7 @@ mod tests { #[test] #[cfg(feature = "v4")] - fn test_from_rng_bytes(){ + fn test_from_rng_bytes() { let b = [ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, From 1ef7e1b2d48374adf92f55ad6a813d6a5d6fbaee Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sun, 18 Mar 2018 16:50:11 +0530 Subject: [PATCH 16/23] add set variant & version name changed to from_random_bytes --- src/lib.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7877fad8a..1971fd23e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -697,7 +697,7 @@ impl Uuid { /// /// let bytes:UuidBytes = [70, 235, 208, 238, 14, 109, 67, 201, 185, 13, 204, 195, 90, 145, 63, 62]; /// - /// let uuid = Uuid::from_rng_bytes(bytes); + /// let uuid = Uuid::from_random_bytes(bytes); /// let uuid = uuid.hyphenated().to_string(); /// /// let expected_uuid = String::from("46ebd0ee-0e6d-43c9-b90d-ccc35a913f3e"); @@ -706,9 +706,11 @@ impl Uuid { /// ``` /// #[cfg(feature = "v4")] - pub fn from_rng_bytes(b: [u8; 16]) -> Uuid { + pub fn from_random_bytes(b: [u8; 16]) -> Uuid { let mut uuid = Uuid { bytes: [0; 16] }; copy_memory(&mut uuid.bytes, &b); + uuid.set_variant(UuidVariant::RFC4122); + uuid.set_version(UuidVersion::Random); uuid } @@ -1827,13 +1829,13 @@ mod tests { #[test] #[cfg(feature = "v4")] - fn test_from_rng_bytes() { + fn test_from_random_bytes() { let b = [ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, ]; - let u = Uuid::from_rng_bytes(b); + let u = Uuid::from_random_bytes(b); let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8"; assert_eq!(u.simple().to_string(), expected); From e5fcba5ceebd87960a87815aca848f10c83c98c2 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Sun, 18 Mar 2018 17:41:50 +0530 Subject: [PATCH 17/23] feature gate removed --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 1971fd23e..355def6a0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -705,7 +705,6 @@ impl Uuid { /// assert_eq!(expected_uuid, uuid); /// ``` /// - #[cfg(feature = "v4")] pub fn from_random_bytes(b: [u8; 16]) -> Uuid { let mut uuid = Uuid { bytes: [0; 16] }; copy_memory(&mut uuid.bytes, &b); From 2b2784e4abab3c6c7a7812c49ac9dfa4a1ebdc92 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Mon, 19 Mar 2018 03:50:20 +0530 Subject: [PATCH 18/23] reroute new_v4 to from_random_bytes --- src/lib.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 355def6a0..d51265268 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -507,11 +507,10 @@ impl Uuid { let mut rng = rand::thread_rng(); - let mut uuid = Uuid { bytes: [0; 16] }; - rng.fill_bytes(&mut uuid.bytes); - uuid.set_variant(UuidVariant::RFC4122); - uuid.set_version(UuidVersion::Random); - uuid + let mut bytes = [0; 16]; + rng.fill_bytes(&mut bytes); + + Uuid::from_random_bytes(bytes) } /// Creates a UUID using a name from a namespace, based on the SHA-1 hash. From ae19a1b787937c97aefc712cbe5997b6f86a9c66 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Mon, 19 Mar 2018 04:06:52 +0530 Subject: [PATCH 19/23] unwanted feature gate removed --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index d51265268..e60ff73f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1826,7 +1826,6 @@ mod tests { } #[test] - #[cfg(feature = "v4")] fn test_from_random_bytes() { let b = [ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, From b64c2e2de43a221558a0bdfdf8c35f01573ce4b2 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Mon, 19 Mar 2018 04:14:35 +0530 Subject: [PATCH 20/23] change expected value because variant & version are added --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index e60ff73f8..08ba2c1db 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1833,7 +1833,7 @@ mod tests { ]; let u = Uuid::from_random_bytes(b); - let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8"; + let expected = "a1a2a3a4b1b241c291d2d3d4d5d6d7d8"; assert_eq!(u.simple().to_string(), expected); } From fe4b1055a8351c508d05c339fbc4276c95f33167 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Tue, 20 Mar 2018 04:07:27 +0530 Subject: [PATCH 21/23] rebased to `copy_from_slice` issue number removed from docs example changed --- src/lib.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 08ba2c1db..687222af1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -684,20 +684,24 @@ impl Uuid { Uuid { bytes: b } } - /// Creates a v4 Uuid from rng bytes (ref issue #170) + /// Creates a v4 Uuid from rng bytes /// /// # Examples /// /// Basic usage: /// + /// `get_random_bytes()` returns 16-byte array filled with random values. + /// It Should be implemented by the user and is not part of the crate. + /// e.g. it could come from the `rand` crate + /// + /// /// ``` /// use uuid::Uuid; /// use uuid::UuidBytes; /// - /// let bytes:UuidBytes = [70, 235, 208, 238, 14, 109, 67, 201, 185, 13, 204, 195, 90, 145, 63, 62]; /// + /// let bytes: [u8; 16] = get_random_bytes(); /// let uuid = Uuid::from_random_bytes(bytes); - /// let uuid = uuid.hyphenated().to_string(); /// /// let expected_uuid = String::from("46ebd0ee-0e6d-43c9-b90d-ccc35a913f3e"); /// @@ -706,7 +710,7 @@ impl Uuid { /// pub fn from_random_bytes(b: [u8; 16]) -> Uuid { let mut uuid = Uuid { bytes: [0; 16] }; - copy_memory(&mut uuid.bytes, &b); + uuid.bytes.copy_from_slice(&b); uuid.set_variant(UuidVariant::RFC4122); uuid.set_version(UuidVersion::Random); uuid From afc61e9215dc30c8c720b48e0fd9a6407a7fb4c2 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Tue, 20 Mar 2018 04:34:45 +0530 Subject: [PATCH 22/23] docs changed back to old style --- src/lib.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 687222af1..139e2c31e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -684,24 +684,20 @@ impl Uuid { Uuid { bytes: b } } - /// Creates a v4 Uuid from rng bytes + /// Creates a v4 Uuid from random bytes (e.g. bytes supplied from `Rand` crate) /// /// # Examples /// /// Basic usage: /// - /// `get_random_bytes()` returns 16-byte array filled with random values. - /// It Should be implemented by the user and is not part of the crate. - /// e.g. it could come from the `rand` crate - /// - /// /// ``` /// use uuid::Uuid; /// use uuid::UuidBytes; /// /// - /// let bytes: [u8; 16] = get_random_bytes(); + /// let bytes:UuidBytes = [70, 235, 208, 238, 14, 109, 67, 201, 185, 13, 204, 195, 90, 145, 63, 62]; /// let uuid = Uuid::from_random_bytes(bytes); + /// let uuid = uuid.hyphenated().to_string(); /// /// let expected_uuid = String::from("46ebd0ee-0e6d-43c9-b90d-ccc35a913f3e"); /// From d4c2963feaecbbf33242a59bd45de72ee4a3fc4d Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Tue, 20 Mar 2018 15:44:10 +0530 Subject: [PATCH 23/23] uuid object created directly --- src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 139e2c31e..06ccd3c08 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -705,8 +705,7 @@ impl Uuid { /// ``` /// pub fn from_random_bytes(b: [u8; 16]) -> Uuid { - let mut uuid = Uuid { bytes: [0; 16] }; - uuid.bytes.copy_from_slice(&b); + let mut uuid = Uuid { bytes: b }; uuid.set_variant(UuidVariant::RFC4122); uuid.set_version(UuidVersion::Random); uuid