Hi everyone, I just started learning Rust and I am running into problems trying to parse and print my csv. I get an error that says
Error: Error(Deserialize { pos: Some(Position { byte: 9, line: 2, record: 1 }), err: DeserializeError { field: None, kind: Message("missing field question
") } })
I checked my CSV file and it is printing all of the records in the CSV. Any help or feedback would be appreciated.
use std::env;
use std::fs;
use csv::Error;
use serde::Deserialize;
#[derive(Deserialize)]
struct Problem {
question: String,
answer: String,
}
fn main() -> Result<(), Error> {
// Get a handle on the arguments from the command line
// args[1] would be the argument given to the application
let args: Vec<String> = env::args().collect();
let csv_filename = &args[1];
//println!("{:?}", args);
let content = fs::read_to_string(csv_filename)
.expect("Something went wrong with accessing the file");
println!("{}", content);
let mut reader = csv::Reader::from_reader(content.as_bytes());
for record in reader.deserialize() {
let record: Problem = record?;
println!("{} {}",record.question, record.answer);
}
Ok(())
}