Skip to main content

usize_into_u32

Function usize_into_u32 

Source
pub const fn usize_into_u32<const N: usize>() -> u32
Expand description

Performs a build-time safe conversion of a usize constant value into a u32.

This checks at compile-time that the conversion is lossless, and triggers a build error if it isn’t.

§Examples

use kernel::num::casts;

// Succeeds because the value of the source fits into the destination's type.
assert_eq!(casts::usize_into_u32::<1usize>(), 1u32);