I often like to use the pattern where a scope returns a tuple. e.g.:
let (person_is_male, person_age) = {
// ...
(false, 42)
}
I also prefer to explicitly specify type information if it is not immediately apparent in a declaration.
If I understand correctly, Rust does not allow me to explicitly type a tuple as follows:
let (person_is_male: bool, person_age: i32) = {
...
(false, 42)
}
Is there a reason why this is disallowed, since Rust needs to infer the type anyway? Are there any other ways to get around this?
You can write
let (person_is_male, person_age): (bool, i32) = {
// ...
(false, 42)
};
3 Likes
Ah. Facepalm moment. I did read the documentation and somehow missed this. Thanks a ton! Hopefully this question shall help more dummies like me.
ExpHP
4
There is an active RFC that will make the desired syntax possible if implemented:
3 Likes