We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
version: 1.1.6
1.1.6
When deserializing a CSV file without headers into a struct (with serde), a UTF-8 error is returned, even though I think the file is valid UTF-8.
use std::path::Path; use csv::{ReaderBuilder, Terminator}; use serde::{de::DeserializeOwned, Deserialize}; fn main() { let filename = std::env::args().next().unwrap(); let records: Vec<PopulationRecord> = read_records(filename).unwrap(); println!("{:?}", records); } #[derive(Debug, Deserialize)] struct PopulationRecord { city: String, state: String, country: String, population: u64, } fn read_records<P: AsRef<Path>, R: DeserializeOwned>(path: P) -> Result<Vec<R>, csv::Error> { let mut rdr = ReaderBuilder::new() .has_headers(false) .terminator(Terminator::CRLF) .from_path(path)?; rdr.deserialize().collect() }
I have downloaded the smallpop-no-headers.csv file from the examples directory. Then running the above program on it gives:
examples
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error(Utf8 { pos: Some(Position { byte: 0, line: 1, record: 0 }), err: Utf8Error { field: 0, valid_up_to: 25 } })', src/main.rs:8:65 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Should give no error, but print the records.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
version:
1.1.6
Problem
When deserializing a CSV file without headers into a struct (with serde), a UTF-8 error is returned, even though I think the file is valid UTF-8.
Code
Observed behaviour
I have downloaded the smallpop-no-headers.csv file from the
examples
directory. Then running the above program on it gives:Expected behaviour
Should give no error, but print the records.
The text was updated successfully, but these errors were encountered: