jk_cosmwasm_std/conversion.rs
1/// Converts an input of type usize to u32.
2///
3/// On 32 bit platforms such as wasm32 this is just a safe cast.
4/// On other platforms the conversion panics for values larger than
5/// `u32::MAX`.
6#[inline]
7pub fn force_to_u32(input: usize) -> u32 {
8 #[cfg(target_pointer_width = "32")]
9 {
10 // usize = u32 on this architecture
11 input as u32
12 }
13 #[cfg(not(target_pointer_width = "32"))]
14 {
15 use std::convert::TryInto;
16 input.try_into().expect("Input exceeds u32 range")
17 }
18}