Hacker News new | ask | show | jobs
by whytevuhuni 2 days ago
Yeah, this has come up a few times when I was coding Rust. From just reading your code I know for sure that i is a usize (indexing is very common), but don't know what j is (I usually expect Rust to throw some kind of "could not infer integer type" compiler error, and it doesn't do that here). I'm guessing maybe i32. Code at the end of the function changing the meaning of code at the beginning of a function has also surprised me a couple times.

In my particular case I'm using Zed with type hints enabled, so the editor displays that expression as `let i: usize = 1;` automatically (which is really useful in a language with type inference, especially with expression as weird/complex as Rust iterator method chains). You're right that I wouldn't know if I were to open the file in a simple text editor.