1pub(crate) fn usize_to_u32(u: usize) -> Option<u32> {
2 #[cfg(not(no_try_from))]
3 {
4 use core::convert::TryFrom;
5
6 u32::try_from(u).ok()
7 }
8
9 #[cfg(no_try_from)]
10 {
11 use core::mem;
12
13 if mem::size_of::<usize>() <= mem::size_of::<u32>() || u <= u32::max_value() as usize {
14 Some(u as u32)
15 } else {
16 None
17 }
18 }
19}
20