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 | fn run() -> Result<(), Box<dyn Error>> { |
| 6 | let mut rdr = csv::Reader::from_reader(io::stdin()); |
| 7 | { |
| 8 | // We nest this call in its own scope because of lifetimes. |
| 9 | let headers = rdr.headers()?; |
| 10 | println!("{:?}", headers); |
| 11 | } |
| 12 | for result in rdr.records() { |
| 13 | let record = result?; |
| 14 | println!("{:?}", record); |
| 15 | } |
| 16 | // We can ask for the headers at any time. There's no need to nest this |
| 17 | // call in its own scope because we never try to borrow the reader again. |
| 18 | let headers = rdr.headers()?; |
| 19 | println!("{:?}", headers); |
| 20 | Ok(()) |
| 21 | } |
| 22 | |
| 23 | fn main() { |
| 24 | if let Err(err) = run() { |
| 25 | println!("{}", err); |
| 26 | process::exit(1); |
| 27 | } |
| 28 | } |