I have a string from a CSV file that contains multiple lines:
Edit. Rust was not in the actual string.
header1,header2,header3
r1v1,r1v2,r1v3
r2v1,r2v2,r2v3
I am trying to push these into a Vec<Vec<String>>:
// the csv is raw_string
let lines = raw_string.lines();
let mut mainVec = Vec::new();
for row in lines {
let mut childVec = Vec::new();
let trimmed = row.trim();
let values = trimmed.split(',').collect();
childVec.push(values);
mainVec.push(childVec.clone());
}
But I get the error
error[E0282]: unable to infer enough type information about `_`
--> src/main.rs:9:13
|
9 | let values = trimmed.split(',').collect();
| ^^^^^^ cannot infer type for `_`
|
= note: type annotations or generic parameter binding required
Vec<Vec<Vec<&str>>>? o_OVec<Vec<String>>", it seems they want aVec<Vec<String>>(twoVecs, not three).childVecshould be part of the answer then.Vec<Vec<String>>, but their code is creating aVec<Vec<Vec<String>>>with an unnecessary one-element vector in the middle.