Comparison operators cannot be chained

For the life of me, I cannot understand what the problem is with:

   Compiling playground v0.0.1 (/playground)
error: comparison operators cannot be chained
  --> src/main.rs:22:25
   |
22 |             (left_start >= right_start & left_end <= right_end) | (right_start >= left_start & right_end <= left_end)
   |                         ^^                        ^^

I am coming from Ruby/Elixir and the likes. So I am probably missing some fundamental Rust related idiom with comparison operators? Not sure.

Thank you so much in advance!
Petros

1 Like

Use && instead of &.

The bitwise-and operator is being parsed like this:

left_start >= (right_start & left_end) <= right_end
3 Likes

Oh Gods of Olympus! Thank you so much @alice. That was it. I have no idea why I insisted on using & instead of &&.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.