Answers for "how to convert usize to i32 in rust"

0

convert string to i32 rust

let my_u8: u8 = "42".parse::<u8>().unwrap();
let my_u32: u32 = "42".parse::<u32>().unwrap();

// or, to be safe, match the `Err`
match "foobar".parse::<i32>() {
  Ok(n) => do_something_with(n),
  Err(e) => weep_and_moan(),
}
Posted by: Guest on December-01-2021
0

convert i32 to usize rust

let num: i32 = 10;
let num_usize: usize = num as usize;
Posted by: Guest on October-11-2020

Browse Popular Code Answers by Language