Initial import of csv-1.1.5.
Bug: 155309706
Change-Id: Id08b46b0989d3b869c4a014d10ea98193b7c3b32
diff --git a/examples/tutorial-perf-alloc-02.rs b/examples/tutorial-perf-alloc-02.rs
new file mode 100644
index 0000000..a3099a1
--- /dev/null
+++ b/examples/tutorial-perf-alloc-02.rs
@@ -0,0 +1,28 @@
+use std::error::Error;
+use std::io;
+use std::process;
+
+fn run() -> Result<u64, Box<dyn Error>> {
+ let mut rdr = csv::Reader::from_reader(io::stdin());
+
+ let mut count = 0;
+ for result in rdr.byte_records() {
+ let record = result?;
+ if &record[0] == b"us" && &record[3] == b"MA" {
+ count += 1;
+ }
+ }
+ Ok(count)
+}
+
+fn main() {
+ match run() {
+ Ok(count) => {
+ println!("{}", count);
+ }
+ Err(err) => {
+ println!("{}", err);
+ process::exit(1);
+ }
+ }
+}