Skip to main content

u32_into_u16

Function u32_into_u16 

Source
pub const fn u32_into_u16<const N: u32>() -> u16
Expand description

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

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::u32_into_u16::<1u32>(), 1u16);