Lines>::count() takes ownership
⚓ Rust 📅 2025-06-09 👤 surdeus 👁️ 14Hi there!
I have following issue, where the count() method for some reasons takes ownership of the object, and returns nothing but size. According to this issue, I can't use this object in the iteration below:
let lines = BufReader::new(File::open(&argument.source)?).lines();
let mut index: HashMap<String, usize> =
HashMap::with_capacity(lines.count()); // `count` takes `lines` ownership
'l: for line in lines { // the `lines` moved (error)
- I want to count the lines, to
HashMapwith optimal capacity, that based on this value.
3 posts - 2 participants
🏷️ rust_feed