Cannot use moved BufReader after for loop with bufreader.lines()

In order to avoid the move, use the Read::by_ref() method. That way, you only borrow the BufReader:

for (index, line) in buffer.by_ref().lines().enumerate() { ... }
//                         ^^^^^^^^^
// you can still use `buffer` here

Leave a Comment