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