Skip to content

Commit

Permalink
use inherint to_be_bytes and to_le_bytes methods, rather than reimple…
Browse files Browse the repository at this point in the history
…menting them with lots of bitshifts
  • Loading branch information
Vrtgs authored Jan 19, 2025
1 parent 2166b44 commit 5d629ce
Showing 1 changed file with 2 additions and 36 deletions.
38 changes: 2 additions & 36 deletions src/builder.rs
Original file line number Diff line number Diff line change
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 5d629ce

Please sign in to comment.