I would like to write the equivalent of 2_u32
, 7_i64
, etc but where the numeric type is given by a type
alias. e.g.,
type Number = u32;
fn main() {
let a = 1_Number; // invalid syntax
let b = 1_u32; // works, but isn't tied to `Number`
let c = 1 as Number; // equivalent to `1_i32 as Number`, which is not what I want
let d = Number::from(1) // requires `Number: From<i32>`, again not what I want
let e = ???
}
So, is there a way to write “variable” numeric literal, whose type is that of a given type
alias?