Hacker News new | ask | show | jobs
by Hamuko 462 days ago
Is x = 57u8 actually idiomatic when compared to x: u8 = 57? I don't remember any Rust resource using that.
3 comments

It's not only not really idiomatic, it's almost never necessary in practice.

I was struggling to think of a time I'd ever given a type annotation to an integer local variable - because normally the place the variable ends up dictates the type.

Local variable becomes part of struct? Struct dictates type. Passed into function? Function dictates type. Multiplied by other variable and then that is passed to function? The type is determined by the function.

It can be necessary if you’re passing it to a generic type/function.
Same, I don’t think that’s idiomatic at all
It doesn’t really make a difference imo.