why does that nor work in Rust: while let Some(next) = walk_to_next(&map, curr_pos, curr_direction) {
curr_direction = next.1;
curr_pos = next.0;
count += 1;
println!("count {count}")
}
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
The code you provided doesn't work in Rust because the walk_to_next function returns a Result value, which is not iterable.
In Rust, the Result type is used to represent a value that may or may not be present, and it's commonly used for handling errors in functions. The Result type has two variants: Ok and Err. Ok contains a value of type T, while Err contains an error message.
In your code, the walk_to_next function returns a Result value, but you're trying to iterate over it as if it were an iterator. However, you can't iterate over a Result value directly. Instead, you need to use pattern matching or the and_then method to extract the value from the Ok variant of the Result.
Here's an example of how you could modify your code to make it work in Rust:
In this example, we use pattern matching to extract the value from the Ok variant of the Result. We also use the break keyword to exit the loop when an error occurs.
Alternatively, you could use the and_then method to chain multiple Result values together and extract the value from the Ok variant. Here's an example of how you could modify your code to use and_then:
code
let mut curr_pos = start_pos;
let mut curr_direction = start_direction;
let mut count = 0;
walk_to_next(&map, curr_pos, curr_direction)
.and_then(|next| walk_to_next(&map, next.