Skip to content

Commit 0152915

Browse files
committed
chore(utils): 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 cd94201 commit 0152915

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
@@ -41,6 +41,15 @@ pub const fn u64_to_usize(num: u64) -> usize {
4141
num as usize
4242
}
4343

44+
/// Safely converts a usize value to a u64 value.
45+
/// This bypasses the Clippy lint check because we only support 64-bit platforms.
46+
#[cfg(target_pointer_width = "64")]
47+
#[inline]
48+
#[allow(clippy::cast_possible_truncation)]
49+
pub const fn usize_to_u64(num: usize) -> u64 {
50+
num as u64
51+
}
52+
4453
/// Converts a usize into a wrapping u32.
4554
#[inline]
4655
pub const fn wrap_usize_to_u32(num: usize) -> Wrapping<u32> {

0 commit comments

Comments
 (0)