From 92ce4c3f9903dbcb30a087d213ca54d041f462d6 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 30 Dec 2021 22:28:52 +0000 Subject: [PATCH] Write the HumanCount implementation with enumerate() --- src/format.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/format.rs b/src/format.rs index 3bb5ef73..16943ba0 100644 --- a/src/format.rs +++ b/src/format.rs @@ -134,11 +134,11 @@ impl fmt::Display for HumanCount { use fmt::Write; let num = self.0.to_string(); - let mut i = num.len(); - for c in num.chars() { + let len = num.len(); + for (idx, c) in num.chars().enumerate() { + let pos = len - idx - 1; f.write_char(c)?; - i -= 1; - if i > 0 && i % 3 == 0 { + if pos > 0 && pos % 3 == 0 { f.write_char(',')?; } }