Skip to content

Commit

Permalink
rename uuid::Uuid::from_uuid_bytes to uuid::Uuid::from_bytes
Browse files Browse the repository at this point in the history
This is inline with from_bytes to from_slice change AND with the uuid prefix
change in #294

Signed-off-by: Hunar Roop Kahlon <hunar.roop@gmail.com>
  • Loading branch information
kinggoesgaming committed Aug 15, 2018
1 parent e43dfe4 commit 0fcc0f7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
28 changes: 13 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl Uuid {
/// ```
#[cfg(feature = "const_fn")]
pub const fn nil() -> Self {
Uuid::from_uuid_bytes([0; 16])
Uuid::from_bytes([0; 16])
}

/// The 'nil UUID'.
Expand Down Expand Up @@ -398,7 +398,7 @@ impl Uuid {
return Err(BytesError::new(D4_LEN, len));
}

Ok(Uuid::from_uuid_bytes([
Ok(Uuid::from_bytes([
(d1 >> 24) as u8,
(d1 >> 16) as u8,
(d1 >> 8) as u8,
Expand Down Expand Up @@ -466,7 +466,7 @@ impl Uuid {

let mut bytes: Bytes = [0; 16];
bytes.copy_from_slice(b);
Ok(Uuid::from_uuid_bytes(bytes))
Ok(Uuid::from_bytes(bytes))
}

/// Creates a `Uuid` using the supplied bytes.
Expand Down Expand Up @@ -503,9 +503,8 @@ impl Uuid {
///
/// let uuid = Uuid::from_uuid_bytes(bytes);
/// ```
// TODO: discuss rename to `from_bytes`
#[cfg(not(feature = "const_fn"))]
pub fn from_uuid_bytes(bytes: Bytes) -> Uuid {
pub fn from_bytes(bytes: Bytes) -> Uuid {
Uuid(bytes)
}

Expand All @@ -524,7 +523,7 @@ impl Uuid {
/// 62,
/// ];
///
/// let uuid = Uuid::from_uuid_bytes(bytes);
/// let uuid = Uuid::from_bytes(bytes);
/// let uuid = uuid.to_hyphenated().to_string();
///
/// let expected_uuid = String::from("46ebd0ee-0e6d-43c9-b90d-ccc35a913f3e");
Expand All @@ -540,11 +539,10 @@ impl Uuid {
///
/// let bytes: Bytes = [4, 54, 67, 12, 43, 2, 98, 76]; // doesn't compile
///
/// let uuid = Uuid::from_uuid_bytes(bytes);
/// let uuid = Uuid::from_bytes(bytes);
/// ```
// TODO: discuss rename to `from_bytes`
#[cfg(feature = "const_fn")]
pub const fn from_uuid_bytes(bytes: Bytes) -> Uuid {
pub const fn from_bytes(bytes: Bytes) -> Uuid {
Uuid(bytes)
}

Expand Down Expand Up @@ -572,7 +570,7 @@ impl Uuid {
/// ```
///
pub fn from_random_bytes(bytes: Bytes) -> Uuid {
let mut uuid = Uuid::from_uuid_bytes(bytes);
let mut uuid = Uuid::from_bytes(bytes);
uuid.set_variant(Variant::RFC4122);
uuid.set_version(Version::Random);
uuid
Expand Down Expand Up @@ -921,7 +919,7 @@ impl Uuid {
});
}

Ok(Uuid::from_uuid_bytes(buffer))
Ok(Uuid::from_bytes(buffer))
}

/// Tests if the UUID is nil
Expand All @@ -942,7 +940,7 @@ mod tests {
fn test_nil() {
let nil = Uuid::nil();
let not_nil = test_util::new();
let from_bytes = Uuid::from_uuid_bytes([
let from_bytes = Uuid::from_bytes([
4, 54, 67, 12, 43, 2, 2, 76, 32, 50, 87, 5, 1, 33, 43, 87,
]);

Expand Down Expand Up @@ -1369,7 +1367,7 @@ mod tests {
0xd4, 0xd5, 0xd6, 0xd7, 0xd8,
];

let u = Uuid::from_bytes(&b).unwrap();
let u = Uuid::from_slice(&b).unwrap();
let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8";

assert_eq!(u.to_simple().to_string(), expected);
Expand All @@ -1382,7 +1380,7 @@ mod tests {
0xd4, 0xd5, 0xd6, 0xd7, 0xd8,
];

let u = Uuid::from_uuid_bytes(b);
let u = Uuid::from_bytes(b);
let expected = "a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8";

assert_eq!(u.to_simple().to_string(), expected);
Expand All @@ -1404,7 +1402,7 @@ mod tests {
0xd4, 0xd5, 0xd6, 0xd7, 0xd8,
];

let u = Uuid::from_bytes(&b_in).unwrap();
let u = Uuid::from_slice(&b_in).unwrap();

let b_out = u.as_bytes();

Expand Down
6 changes: 3 additions & 3 deletions src/serde_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'de> Deserialize<'de> for Uuid {
self,
value: &[u8],
) -> Result<Uuid, E> {
Uuid::from_bytes(value).map_err(E::custom)
Uuid::from_slice(value).map_err(E::custom)
}
}

Expand All @@ -76,7 +76,7 @@ impl<'de> Deserialize<'de> for Uuid {
self,
value: &[u8],
) -> Result<Uuid, E> {
Uuid::from_bytes(value).map_err(E::custom)
Uuid::from_slice(value).map_err(E::custom)
}
}

Expand Down Expand Up @@ -108,7 +108,7 @@ mod tests {
use serde_test::Configure;

let uuid_bytes = b"F9168C5E-CEB2-4F";
let u = Uuid::from_bytes(uuid_bytes).unwrap();
let u = Uuid::from_slice(uuid_bytes).unwrap();
serde_test::assert_tokens(
&u.compact(),
&[serde_test::Token::Bytes(uuid_bytes)],
Expand Down
4 changes: 2 additions & 2 deletions src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
use prelude::*;

pub fn new() -> Uuid {
Uuid::from_uuid_bytes([
Uuid::from_bytes([
0xF9, 0x16, 0x8C, 0x5E, 0xCE, 0xB2, 0x4F, 0xAA, 0xB6, 0xBF, 0x32, 0x9B,
0xF3, 0x9F, 0xA1, 0xE4,
])
}

pub fn new2() -> Uuid {
Uuid::from_uuid_bytes([
Uuid::from_bytes([
0xF9, 0x16, 0x8C, 0x5E, 0xCE, 0xB2, 0x4F, 0xAB, 0xB6, 0xBF, 0x32, 0x9B,
0xF3, 0x9F, 0xA1, 0xE4,
])
Expand Down
2 changes: 1 addition & 1 deletion src/u128_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl From<u128> for Uuid {
byteorder::NativeEndian::write_u128(&mut bytes[..], f);
}

Uuid::from_uuid_bytes(bytes)
Uuid::from_bytes(bytes)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl Uuid {
context.consume(namespace.as_bytes());
context.consume(name);

let mut uuid = Uuid::from_uuid_bytes(context.compute().into());
let mut uuid = Uuid::from_bytes(context.compute().into());

uuid.set_variant(Variant::RFC4122);
uuid.set_version(Version::Md5);
Expand Down

0 comments on commit 0fcc0f7

Please sign in to comment.