3 ms·
For the type after identifier, the converse is what you see in C family languages. For example: // in C int x = ... // in Rust let x: i32 = ..
by onei 5y ago
For the type after identifier, the converse is what you see in C family languages. For example:
// in C
int x = ...
// in Rust
let x: i32 = ...
There's a couple of things that Rust can do better than C here. First, is that Rust is easier to parse because you know that let begins a variable declaration. If we look at C, maybe it's a variable, maybe it's a function and you have to get past the identifier to figure that out. The second more user-facing change is that you can omit the type in Rust if you can derive it from somewhere else, e.g. the return type of a function call or a primitive.