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 {