Reputation: 16352
I want to convert a u8
to an i32
. I used to do:
use std::num::ToPrimitive;
fn main () {
// ...
// Other code
// ...
let int32 : i32 = u8Value.to_i32().unwrap();
}
This code does not compile in the recent nightlies. It complains that the ToPrimitive trait is unstable and will likely be removed.
Upvotes: 0
Views: 113
Reputation: 430466
Use as
to cast numeric types:
fn main () {
let u8_value: u8 = 42;
let i32_value: i32 = u8_value as i32;
}
Upvotes: 2