From a06e009594f63937dcf40467447e3bcb4c181c15 Mon Sep 17 00:00:00 2001 From: Hunar Roop Kahlon Date: Thu, 31 Oct 2019 22:32:09 -0700 Subject: [PATCH 1/4] move Builder to the root module Signed-off-by: Hunar Roop Kahlon --- src/builder/mod.rs | 13 +++++++------ src/lib.rs | 25 ++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/builder/mod.rs b/src/builder/mod.rs index 784558aa5..1434e4527 100644 --- a/src/builder/mod.rs +++ b/src/builder/mod.rs @@ -276,11 +276,12 @@ impl Uuid { /// .set_version(Version::Random) /// .build(); /// ``` -#[allow(missing_copy_implementations)] -#[derive(Debug)] -pub struct Builder(crate::Bytes); +// TODO: remove in 1.0.0 +#[allow(dead_code)] +#[deprecated] +pub type Builder = crate::Builder; -impl Builder { +impl crate::Builder { /// Creates a `Builder` using the supplied big-endian bytes. /// /// # Examples @@ -398,13 +399,13 @@ impl Builder { Uuid::from_fields(d1, d2, d3, d4).map(|uuid| { let bytes = *uuid.as_bytes(); - Builder::from_bytes(bytes) + crate::Builder::from_bytes(bytes) }) } /// Creates a `Builder` from a big-endian 128bit value. pub fn from_u128(v: u128) -> Self { - Builder::from_bytes(*Uuid::from_u128(v).as_bytes()) + crate::Builder::from_bytes(*Uuid::from_u128(v).as_bytes()) } /// Creates a `Builder` with an initial [`Uuid::nil`]. diff --git a/src/lib.rs b/src/lib.rs index c3d0d225d..3ecca7095 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -194,7 +194,30 @@ mod winapi_support; use crate::std::{fmt, str}; -pub use crate::{builder::Builder, error::Error}; +pub use crate::{error::Error}; + +/// A builder struct for creating a UUID. +/// +/// # Examples +/// +/// Creating a v4 UUID from externally generated bytes: +/// +/// ``` +/// use uuid::{Builder, Variant, Version}; +/// +/// # let rng = || [ +/// # 70, 235, 208, 238, 14, 109, 67, 201, 185, 13, 204, 195, 90, +/// # 145, 63, 62, +/// # ]; +/// let random_bytes = rng(); +/// let uuid = Builder::from_bytes(random_bytes) +/// .set_variant(Variant::RFC4122) +/// .set_version(Version::Random) +/// .build(); +/// ``` +#[allow(missing_copy_implementations)] +#[derive(Debug)] +pub struct Builder(Bytes); /// A 128-bit (16 byte) buffer containing the ID. pub type Bytes = [u8; 16]; From 22dce9ca9e9b7282b34188ea64ff0a85b3fdc723 Mon Sep 17 00:00:00 2001 From: Hunar Roop Kahlon Date: Sun, 6 Sep 2020 16:08:28 -0700 Subject: [PATCH 2/4] fix clippy errors Signed-off-by: Hunar Roop Kahlon --- src/parser/mod.rs | 2 +- src/v3.rs | 2 +- src/v5.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 4f8e69e1d..9243564b2 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -33,7 +33,7 @@ fn len_matches_any(len: usize, crits: &[usize]) -> bool { /// (inclusive). #[allow(dead_code)] fn len_matches_range(len: usize, min: usize, max: usize) -> bool { - for crit in min..(max+1) { + for crit in min..=max { if len == crit { return true; } diff --git a/src/v3.rs b/src/v3.rs index c598239e7..19eabff57 100644 --- a/src/v3.rs +++ b/src/v3.rs @@ -28,7 +28,7 @@ impl Uuid { let computed = context.compute(); let bytes = computed.into(); - let mut builder = crate::builder::Builder::from_bytes(bytes); + let mut builder = crate::Builder::from_bytes(bytes); builder .set_variant(Variant::RFC4122) diff --git a/src/v5.rs b/src/v5.rs index b71d6d433..78e800f45 100644 --- a/src/v5.rs +++ b/src/v5.rs @@ -29,7 +29,7 @@ impl Uuid { let mut bytes = crate::Bytes::default(); bytes.copy_from_slice(&buffer[..16]); - let mut builder = crate::builder::Builder::from_bytes(bytes); + let mut builder = crate::Builder::from_bytes(bytes); builder .set_variant(Variant::RFC4122) .set_version(Version::Sha1); From 0c2d9cf8f489e900256584bc21e21813937de044 Mon Sep 17 00:00:00 2001 From: Hunar Roop Kahlon Date: Sun, 6 Sep 2020 18:49:10 -0700 Subject: [PATCH 3/4] fix v4 Builder path Signed-off-by: Hunar Roop Kahlon --- src/v4.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v4.rs b/src/v4.rs index f4b75ec49..45d2003e5 100644 --- a/src/v4.rs +++ b/src/v4.rs @@ -29,7 +29,7 @@ impl Uuid { let mut bytes = [0u8; 16]; getrandom::getrandom(&mut bytes)?; - let uuid = crate::builder::Builder::from_bytes(bytes) + let uuid = crate::Builder::from_bytes(bytes) .set_variant(Variant::RFC4122) .set_version(Version::Random) .build(); From f819d3bb05107385bec9dd9bc0510a74cb04f593 Mon Sep 17 00:00:00 2001 From: Hunar Roop Kahlon Date: Sun, 6 Sep 2020 18:56:20 -0700 Subject: [PATCH 4/4] fix fmt issues Signed-off-by: Hunar Roop Kahlon --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 12e8198f1..8f4df9625 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -198,7 +198,7 @@ mod winapi_support; use crate::std::{fmt, str}; -pub use crate::{error::Error}; +pub use crate::error::Error; /// A builder struct for creating a UUID. ///