Skip to content

Commit

Permalink
use u128 methods, rather than reimplementing to_be_bytes and to_le_bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Vrtgs committed Jan 7, 2025
1 parent 5cbe0ce commit da1b94d
Showing 1 changed file with 3 additions and 37 deletions.
40 changes: 3 additions & 37 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl Uuid {
(d1 >> 8) as u8,
(d1 >> 16) as u8,
(d1 >> 24) as u8,
(d2) as u8,
d2 as u8,
(d2 >> 8) as u8,
d3 as u8,
(d3 >> 8) as u8,
Expand Down Expand Up @@ -204,24 +204,7 @@ impl Uuid {
/// );
/// ```
pub const fn from_u128(v: u128) -> Self {
Uuid::from_bytes([
(v >> 120) as u8,
(v >> 112) as u8,
(v >> 104) as u8,
(v >> 96) as u8,
(v >> 88) as u8,
(v >> 80) as u8,
(v >> 72) as u8,
(v >> 64) as u8,
(v >> 56) as u8,
(v >> 48) as u8,
(v >> 40) as u8,
(v >> 32) as u8,
(v >> 24) as u8,
(v >> 16) as u8,
(v >> 8) as u8,
v as u8,
])
Uuid::from_bytes(v.to_be_bytes())
}

/// Creates a UUID from a 128bit value in little-endian order.
Expand All @@ -247,24 +230,7 @@ impl Uuid {
/// );
/// ```
pub const fn from_u128_le(v: u128) -> Self {
Uuid::from_bytes([
v as u8,
(v >> 8) as u8,
(v >> 16) as u8,
(v >> 24) as u8,
(v >> 32) as u8,
(v >> 40) as u8,
(v >> 48) as u8,
(v >> 56) as u8,
(v >> 64) as u8,
(v >> 72) as u8,
(v >> 80) as u8,
(v >> 88) as u8,
(v >> 96) as u8,
(v >> 104) as u8,
(v >> 112) as u8,
(v >> 120) as u8,
])
Uuid::from_bytes(v.to_le_bytes())
}

/// Creates a UUID from two 64bit values.
Expand Down

0 comments on commit da1b94d

Please sign in to comment.