Skip to content

Commit bcc4b77

Browse files
committed
chore: add usize_to_u64 to utils
Usize to u64 is safe as Firecracker only supports 64bit platforms where usize == u64. Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent 25d2e72 commit bcc4b77

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/utils/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ pub const fn u64_to_usize(num: u64) -> usize {
5050
num as usize
5151
}
5252

53+
/// Safely converts a usize value to a u64 value.
54+
/// This bypasses the Clippy lint check because we only support 64-bit platforms.
55+
#[cfg(target_pointer_width = "64")]
56+
#[inline]
57+
#[allow(clippy::cast_possible_truncation)]
58+
pub const fn usize_to_u64(num: usize) -> u64 {
59+
num as u64
60+
}
61+
5362
/// Converts a usize into a wrapping u32.
5463
#[inline]
5564
pub const fn wrap_usize_to_u32(num: usize) -> Wrapping<u32> {

0 commit comments

Comments
 (0)