From c1b058ce4e252e488b8d0346d9ce0133a3074336 Mon Sep 17 00:00:00 2001 From: Vecna Date: Mon, 26 Feb 2024 18:01:07 -0500 Subject: [PATCH] cargo-fmt --- src/extra_info.rs | 15 +++++++-------- src/lib.rs | 33 ++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/extra_info.rs b/src/extra_info.rs index 711d292..47dbbbb 100644 --- a/src/extra_info.rs +++ b/src/extra_info.rs @@ -45,7 +45,9 @@ fn get_extra_info_or_error(entry: &HashMap) -> Result) -> Result Self { Self { - info_by_country: BTreeMap::>::new(), + info_by_country: BTreeMap::>::new(), } } - pub fn add_info(&mut self, info_type: BridgeInfoType, count_per_country: &BTreeMap::) { + pub fn add_info( + &mut self, + info_type: BridgeInfoType, + count_per_country: &BTreeMap, + ) { for country in count_per_country.keys() { if self.info_by_country.contains_key(country) { let info = self.info_by_country.get_mut(country).unwrap(); if !info.contains_key(&info_type) { - info.insert(info_type, *count_per_country.get(&country.to_string()).unwrap()); + info.insert( + info_type, + *count_per_country.get(&country.to_string()).unwrap(), + ); } else if info_type == BridgeInfoType::BridgeIps { // Use newest value we've seen today if info.get(&info_type).unwrap() < count_per_country.get(country).unwrap() { - info.insert(BridgeInfoType::BridgeIps, *count_per_country.get(&country.to_string()).unwrap()); + info.insert( + BridgeInfoType::BridgeIps, + *count_per_country.get(&country.to_string()).unwrap(), + ); } } else { - let new_count = info.get(&info_type).unwrap() + *count_per_country.get(&country.to_string()).unwrap(); + let new_count = info.get(&info_type).unwrap() + + *count_per_country.get(&country.to_string()).unwrap(); info.insert(info_type, new_count); } } else { let mut info = BTreeMap::::new(); - info.insert(info_type, *count_per_country.get(&country.to_string()).unwrap()); + info.insert( + info_type, + *count_per_country.get(&country.to_string()).unwrap(), + ); self.info_by_country.insert(country.to_string(), info); } } @@ -201,15 +215,12 @@ pub fn add_extra_info_to_db(db: &Db, extra_info: ExtraInfo) { // If we already have an entry, compare it with the new one. For each // country:count mapping, use the greater of the two counts. if bridge_info.info_by_day.contains_key(&extra_info.date) { - let daily_bridge_info = bridge_info - .info_by_day - .get_mut(&extra_info.date) - .unwrap(); + let daily_bridge_info = bridge_info.info_by_day.get_mut(&extra_info.date).unwrap(); daily_bridge_info.add_info(BridgeInfoType::BridgeIps, &extra_info.bridge_ips); } else { // No existing entry; make a new one. let mut daily_bridge_info = DailyBridgeInfo { - info_by_country: BTreeMap::>::new(), + info_by_country: BTreeMap::>::new(), }; daily_bridge_info.add_info(BridgeInfoType::BridgeIps, &extra_info.bridge_ips); bridge_info