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
More Related Contents:
- Traits and Rust
- How to get a reference to a concrete type from a trait object?
- Why can impl trait not be used to return multiple / conditional types?
- How do I implement a trait I don’t own for a type I don’t own?
- What makes something a “trait object”?
- Is it possible to use `impl Trait` as a function’s return type in a trait definition?
- How do I return an instance of a trait from a method?
- I implemented a trait for another trait but cannot call methods from both traits
- Why would I implement methods on a trait instead of as part of the trait?
- How does the mechanism behind the creation of boxed traits work?
- Trait implementation for both a trait object and for direct implementors of the trait
- Why is the `Sized` bound necessary in this trait?
- How can I implement Rust’s Copy trait?
- Is there any trait that specifies numeric functionality?
- Understanding Traits and Object Safety
- How do I pass a closure through raw pointers as an argument to a C function?
- Can’t implement a trait I don’t own for all types that implement a trait I do own
- How do I specify that a struct field must implement a trait?
- Rust equivalent to Swift’s extension methods to a protocol?
- Do I have to implement a trait twice when implementing it for both reference and non-reference types?
- How do I stop iteration and return an error when Iterator::map returns a Result::Err?
- Are polymorphic variables allowed?
- Efficiently mutate a vector while also iterating over the same vector
- How can I put an async function into a map in Rust?
- How do I synchronously return a value calculated in an asynchronous Future?
- Removing elements from a Vec based on some condition [duplicate]
- How can I change enum variant while moving the field to the new variant?
- What’s the difference between using the return statement and omitting the semicolon in Rust?
- The trait `FnMut` is not implemented for `String` when trying to split a string
- HashMap borrow issue when trying to implement find or insert