message: Add ref_to_u32
diff: @@ -12,6 +12,14 @@ pub fn to_u32<T: TryInto<u32> + Display + Copy>(input: T) -> VmResult<u32> {
  })
  }
  +/// Safely converts input of type &T to u32.
  +/// Errors with a cosmwasm_vm::errors::VmError::ConversionErr if conversion cannot be done.
  +pub fn ref_to_u32<T: TryInto<u32> + ToString + Clone>(input: &T) -> VmResult<u32> {
  + input.clone().try_into().map_err(|_| {
  + VmError::conversion_err(type_name::<T>(), type_name::<u32>(), input.to_string())
  + })
  +}
  +
  /// Safely converts input of type T to i32.
  /// Errors with a cosmwasm_vm::errors::VmError::ConversionErr if conversion cannot be done.
  ///
  @@ -98,6 +106,47 @@ mod test {
  };
  }
  + #[test]
  + fn ref_to_u32_works() {
  + // i32
  + assert_eq!(ref_to_u32(&0i32).unwrap(), 0);
  + assert_eq!(ref_to_u32(&1i32).unwrap(), 1);
  + assert_eq!(ref_to_u32(&2147483647i32).unwrap(), 2147483647);
  + match ref_to_u32(&-1i32).unwrap_err() {
  + VmError::ConversionErr {
  + from_type,
  + to_type,
  + input,
  + ..
  + } => {
  + assert_eq!(from_type, "i32");
  + assert_eq!(to_type, "u32");
  + assert_eq!(input, "-1");
  + }
  + err => panic!("Unexpected error: {:?}", err),
  + };
  +
  + // usize
  + assert_eq!(ref_to_u32(&0usize).unwrap(), 0);
  + assert_eq!(ref_to_u32(&1usize).unwrap(), 1);
  + assert_eq!(ref_to_u32(&2147483647usize).unwrap(), 2147483647);
  + assert_eq!(ref_to_u32(&2147483648usize).unwrap(), 2147483648);
  + assert_eq!(ref_to_u32(&4294967295usize).unwrap(), 4294967295);
  + match ref_to_u32(&4294967296usize).unwrap_err() {
  + VmError::ConversionErr {
  + from_type,
  + to_type,
  + input,
  + ..
  + } => {
  + assert_eq!(from_type, "usize");
  + assert_eq!(to_type, "u32");
  + assert_eq!(input, "4294967296");
  + }
  + err => panic!("Unexpected error: {:?}", err),
  + };
  + }
  +
  #[test]
  fn to_i32_works_for_usize() {
  assert_eq!(to_i32(0usize).unwrap(), 0);
  