I am trying to implement this Reddit coding challenge, but I get an error I don't understand and my searching was of no help.
#[derive(Debug)]
struct State {}
fn button_clicked(state: State) -> State {
state
}
fn cycle_complete(state: State) -> State {
state
}
fn main() {
let actions = [
button_clicked,
cycle_complete,
button_clicked,
button_clicked,
button_clicked,
button_clicked,
button_clicked
];
let mut state = State {};
for action in actions.iter() {
state = action(state);
println!("State = {:?}", state);
}
}
When I try to build this, I get:
$ cargo build
Compiling garageautomata v0.1.0 (file:///Users/zeisss/p/rust-example/garageautomata)
src/main.rs:41:9: 41:23 error: mismatched types:
expected `fn(State) -> State {button_clicked}`,
found `fn(State) -> State {cycle_complete}`
(expected fn item,
found a different fn item) [E0308]
src/main.rs:41 cycle_complete,
^~~~~~~~~~~~~~
src/main.rs:41:9: 41:23 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to previous error
error: Could not compile `garageautomata`.
To learn more, run the command again with --verbose.
(since the code is shortened, line 41 refers to first occurrence of cycle_complete
in main
).
I am using Rust 1.8.0.