1 #![allow(dead_code)]
2 use std::{error::Error, io, process};
3
4 use serde::Deserialize;
5
6 #[derive(Debug, Deserialize)]
7 #[serde(rename_all = "PascalCase")]
8 struct Record {
9 country: String,
10 city: String,
11 accent_city: String,
12 region: String,
13 population: Option<u64>,
14 latitude: f64,
15 longitude: f64,
16 }
17
run() -> Result<u64, Box<dyn Error>>18 fn run() -> Result<u64, Box<dyn Error>> {
19 let mut rdr = csv::Reader::from_reader(io::stdin());
20
21 let mut count = 0;
22 for result in rdr.deserialize() {
23 let record: Record = result?;
24 if record.country == "us" && record.region == "MA" {
25 count += 1;
26 }
27 }
28 Ok(count)
29 }
30
main()31 fn main() {
32 match run() {
33 Ok(count) => {
34 println!("{}", count);
35 }
36 Err(err) => {
37 println!("{}", err);
38 process::exit(1);
39 }
40 }
41 }
42