尝试第二次访问变量sentences会导致
value used here after move
,我想了解如何在不引起此问题的情况下存储总数。
我尝试复制迭代器,但无法找到使其工作的方法或正确的方法。extern crate regex;
use std::fs::File;
use std::path::Path;
use std::io::{BufReader, BufRead};
fn main() {
let sentences_path = Path::new("csv/testSentences.csv");
let sentences = BufReader::new(File::open(&sentences_path).unwrap());
let total = sentences.lines().count();
for (index, sentence) in sentences.lines().enumerate() {
let line = sentence.unwrap();
println!("Processed {} of {}, {}", index, total, line);
}
println!("Total {}", total);
}