Let a :u64 =1; let b :u64=2; let c :u64 = 3; seems awkward

? why cant rustc accept let :u64 a=1, b=2, c=3 ;
Same for let mut.
This would ease the burden of converting other language source code > Rust

More often than not, you don’t actually need to specify the type. In particular if you use a, b, and c in places that clearly expect an u64.

So the code would become

let a = 1;
let b = 2;
let c = 3;

You can also use tuples and destructuring if you like, e.g.

let (a, b, c) = (1, 2, 3);

or arrays, if the values are all the same type

let [a, b, c] = [1, 2, 3];

With arrays, you can also fairly easily add the type back in if you do need it.

let [a, b, c]: [u64; 3] = [1, 2, 3];


let [a, b, c] = [1, 2, 3 as u64];

You can even go towards more “creative” alternatives, e.g.

let [a, b, c]: [u64; 3];
a = 1;
b = 2;
c = 3;

if you really feel like you need something that looks similar to a = 1, b = 2, c = 3.


The current syntax is let <pattern> [: <type>] [= <expression>], so the <type> applies to the whole <pattern>. Notably, you can declare variables of different types in a single let:

let (a, b, c): (u64, i32, String);

An alternative, visually similar syntax that gives the same type to all the bound variables would probably be confusing, and doesn't seem to carry its weight IMO (as already pointed out, it's usual in Rust not to write out the types at all).

I don't think I agree, but I'm not sure what you mean. Can you give an example of how a feature like this would help someone translate code written in another language?

1 Like

Declaring variables is not the hard part of converting code from one language to another. It's not even close.


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.