Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use inherent to_be_bytes and to_le_bytes methods #788

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading