Skip to content

Commit

Permalink
Merge #441
Browse files Browse the repository at this point in the history
441: Move Builder to base module r=Dylan-DPC a=kinggoesgaming

**I'm submitting a(n)** other

# Description
Move the `Builder` 

# Motivation
We `pub use` the builder already. But since the `Builder itself is important, it seems logical to bring it out

# Tests
Tests should pass as is.


Co-authored-by: Hunar Roop Kahlon <[email protected]>
  • Loading branch information
bors[bot] and kinggoesgaming authored Sep 7, 2020
2 parents c33d8a6 + f819d3b commit fec6ad3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
13 changes: 7 additions & 6 deletions src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`].
Expand Down
25 changes: 24 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,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];
Expand Down
2 changes: 1 addition & 1 deletion src/v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fec6ad3

Please sign in to comment.