C:
int a,b,c;
Rust:
let (a,b,c): (i32,i32,i32);???
How to do it in one assignment?
C:
int a,b,c;
Rust:
let (a,b,c): (i32,i32,i32);???
How to do it in one assignment?
I'm slightly confused by what you mean, there are no assignments there. If you explicitly specify the type you can't avoid repeating it, but you don't have to.
let (a, b, c);
This is perfectly valid Rust as long as rustc is able to infer the types of a, b and c later on, e.g.
a = 5_i32;
b = 6 + 7;
c = 8;
Thanks.
It's worth noting that in Rust, by contrast with C,
Thanks.
So, to sum up, you should probably write this as:
let (a, b, c) = (1, 2, 3);
Or, if you wanted to initialize them all to the same value you can use array patterns, which scales a bit better for more bindings:
let [a, b, c] = [0_i32; 3];
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.