This is problematic as the u8-to-u7 is range-checked, but the u32-to-u8 is not. This can be addressed by u7::new(x.try_into().unwrap()), but that's a) clunky and b) not const safe.
A good fix would be to provide new_from_u32 (or from_u32?) and try_new_from_u32/try_from_u32 (as well as other built-in types).
In our codebase we see this pattern quite a lot:
This is problematic as the u8-to-u7 is range-checked, but the u32-to-u8 is not. This can be addressed by
u7::new(x.try_into().unwrap())
, but that's a) clunky and b) not const safe.A good fix would be to provide
new_from_u32
(orfrom_u32
?) andtry_new_from_u32
/try_from_u32
(as well as other built-in types).