Jakub Kotur | c72d720 | 2020-12-21 17:28:15 +0100 | [diff] [blame^] | 1 | use std::error::Error; |
| 2 | use std::io; |
| 3 | use std::process; |
| 4 | |
| 5 | // This introduces a type alias so that we can conveniently reference our |
| 6 | // record type. |
| 7 | type Record = (String, String, Option<u64>, f64, f64); |
| 8 | |
| 9 | fn run() -> Result<(), Box<dyn Error>> { |
| 10 | let mut rdr = csv::Reader::from_reader(io::stdin()); |
| 11 | // Instead of creating an iterator with the `records` method, we create |
| 12 | // an iterator with the `deserialize` method. |
| 13 | for result in rdr.deserialize() { |
| 14 | // We must tell Serde what type we want to deserialize into. |
| 15 | let record: Record = result?; |
| 16 | println!("{:?}", record); |
| 17 | } |
| 18 | Ok(()) |
| 19 | } |
| 20 | |
| 21 | fn main() { |
| 22 | if let Err(err) = run() { |
| 23 | println!("{}", err); |
| 24 | process::exit(1); |
| 25 | } |
| 26 | } |