diff --git a/src/geoip.rs b/src/geoip.rs index 9e2320e43..825a535ca 100644 --- a/src/geoip.rs +++ b/src/geoip.rs @@ -1,4 +1,4 @@ -use std::collections::{HashMap}; +use std::collections::{BTreeMap, HashMap}; use std::io; use std::io::{ErrorKind}; use std::io::ErrorKind::Other; @@ -67,14 +67,14 @@ impl IpGeolocationIoClient { pub(crate) struct CachedIpGeolocationIpClient { path: String, client: IpGeolocationIoClient, - map: HashMap, + map: BTreeMap, } impl CachedIpGeolocationIpClient { pub(crate) async fn new(filename: String) -> io::Result { let cache_str = tokio::fs::read_to_string(filename.as_str()).await?; - let map: HashMap = serde_json::de::from_str(cache_str.as_str()) + let map: BTreeMap = serde_json::de::from_str(cache_str.as_str()) .map_err(|err| io::Error::new(Other, err))?; let client = CachedIpGeolocationIpClient { @@ -99,7 +99,7 @@ impl CachedIpGeolocationIpClient { } pub(crate) async fn save(&self) -> io::Result<()> { - let str = serde_json::ser::to_string(&self.map) + let str = serde_json::ser::to_string_pretty(&self.map) .map_err(|err| io::Error::new(Other, err))?; tokio::fs::write(self.path.as_str(), str).await } @@ -112,4 +112,4 @@ impl CachedIpGeolocationIpClient { self.map.insert(String::from(hostname_or_ip), geo_ip_data.clone()); Ok(geo_ip_data) } -} \ No newline at end of file +}