From 7612956830d793d1a332ca5ab3702fb79968a0e7 Mon Sep 17 00:00:00 2001 From: Ishan Jain Date: Tue, 21 Jan 2025 16:16:02 +0530 Subject: [PATCH] fix: improve Display impl on Data --- geofw/src/maxmind.rs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/geofw/src/maxmind.rs b/geofw/src/maxmind.rs index bb4e119..ac0666e 100644 --- a/geofw/src/maxmind.rs +++ b/geofw/src/maxmind.rs @@ -52,9 +52,9 @@ impl Display for Data<'_> { match self { Data::String(s) => f.write_str(&String::from_utf8_lossy(s)), Data::Double(s) => write!(f, "{s}"), - Data::Bytes(s) => f.write_fmt(format_args!("{:?}", s)), - Data::U16(s) => f.write_str(&s.to_string()), - Data::U32(s) => f.write_str(&s.to_string()), + Data::Bytes(s) => write!(f, "{s:?}"), + Data::U16(s) => write!(f, "{s}"), + Data::U32(s) => write!(f, "{s}"), Data::Map(hash_map) => { for (k, v) in hash_map { f.write_fmt(format_args!("{} => {}\n", String::from_utf8_lossy(k), v)) @@ -62,9 +62,9 @@ impl Display for Data<'_> { } Ok(()) } - Data::I32(s) => f.write_str(&s.to_string()), - Data::U64(s) => f.write_str(&s.to_string()), - Data::U128(s) => f.write_str(&s.to_string()), + Data::I32(s) => write!(f, "{s}"), + Data::U64(s) => write!(f, "{s}"), + Data::U128(s) => write!(f, "{s}"), Data::Array(vec) => { for (i, v) in vec.iter().enumerate() { f.write_fmt(format_args!("index = {} value = {}\n", i, v)) @@ -73,9 +73,9 @@ impl Display for Data<'_> { Ok(()) } Data::DataCache => todo!(), - Data::End => f.write_str("END"), - Data::Boolean(s) => f.write_str(&s.to_string()), - Data::Float(s) => f.write_str(&s.to_string()), + Data::End => write!(f, "END"), + Data::Boolean(s) => write!(f, "{s}"), + Data::Float(s) => write!(f, "{s}"), } } } @@ -287,11 +287,8 @@ impl MaxmindDB { } } - fn read_map(&self, offset: usize, read: usize, length: usize) -> (Data, usize) { + fn read_map(&self, offset: usize, mut read: usize, mut length: usize) -> (Data, usize) { let mut map = FxHashMap::with_capacity_and_hasher(length, Default::default()); - // length is number of elements - let mut length = length; - let mut read = read; while length > 0 { let (key, r) = self.read_data(offset + read);