This question uses syntax that predates Rust 1.0, but the concepts are universal and many answers have been updated to reflect stable Rust 1.0.
This question is about a very basic thing that a programmer might try while learning Rust.
You couldn't ask a simpler question about the Rust language, I don't think, but I'm a programmer with 30 years experience, and I can't figure it out.
I think it has something to do with int::range
and closures.
Here's what I wrote in a very early version of Rust (pre 1.0).
fn main() {
int::range(0, 100, {|i|
io::println(i);
});
}
This creates lovely error messages that I have no idea how to fix:
hello.rs:3:19: 5:2 error: mismatched types: expected `&fn(int) -> bool` but found `()` (expected fn but found ())
hello.rs:3 int::range(0, 100, {|i|
hello.rs:4 io::println(i);
hello.rs:5 });
It's funny how it printed out my entire function body, but still I have no idea what that &fn(int) ->b ool
thing means. I vaguely suspect that having a body of an iterator's closure not declare any return type is explicitly disallowed in Rust, which confuses me.