Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Lines>::count() takes ownership
Hi 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)
HashMap
with optimal capacity, that based on this value.3 posts - 2 participants
🏷️ rust_feed