From 1bd26fb2eee0b1d6da9595da5def0cfd333b67df Mon Sep 17 00:00:00 2001 From: Michael Bryan Date: Sat, 2 Sep 2017 18:52:11 +0800 Subject: [PATCH] Fixed the rendering bug --- src/book/summary.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/book/summary.rs b/src/book/summary.rs index a8a16623..46f477e5 100644 --- a/src/book/summary.rs +++ b/src/book/summary.rs @@ -493,13 +493,10 @@ pub struct SectionNumber(pub Vec); impl Display for SectionNumber { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - let dotted_number: String = self.0 - .iter() - .map(|i| i.to_string()) - .collect::>() - .join("."); - - write!(f, "{}", dotted_number) + for item in &self.0 { + write!(f, "{}.", item)?; + } + Ok(()) } } @@ -523,9 +520,9 @@ mod tests { #[test] fn section_number_has_correct_dotted_representation() { let inputs = vec![ - (vec![0], "0"), - (vec![1, 3], "1.3"), - (vec![1, 2, 3], "1.2.3"), + (vec![0], "0."), + (vec![1, 3], "1.3."), + (vec![1, 2, 3], "1.2.3."), ]; for (input, should_be) in inputs {