blob: ddaa7569f695b05da0ca90cd5d512d10e4702047 [file] [log] [blame]
Jakub Koturc72d7202020-12-21 17:28:15 +01001use std::error::Error;
2use std::io;
3use std::process;
4
5fn 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
23fn main() {
24 if let Err(err) = run() {
25 println!("{}", err);
26 process::exit(1);
27 }
28}