diff --git a/src/lib.rs b/src/lib.rs index 7a50d85..8f34e23 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -173,16 +173,16 @@ impl ColoredString { // TODO: BoyScoutRule let reset = "\x1B[0m"; let style = self.compute_style(); - let matches: Vec = self.input + let matches: Vec = self + .input .match_indices(reset) .map(|(idx, _)| idx) .collect(); - let mut idx_in_matches = 0; let mut input = self.input.clone(); input.reserve(matches.len() * style.len()); - for offset in matches { + for (idx_in_matches, offset) in matches.into_iter().enumerate() { // shift the offset to the end of the reset sequence and take in account // the number of matches we have escaped (which shift the index to insert) let mut offset = offset + reset.len() + idx_in_matches * style.len(); @@ -191,8 +191,6 @@ impl ColoredString { input.insert(offset, cchar); offset += 1; } - - idx_in_matches += 1; } input diff --git a/src/style.rs b/src/style.rs index ba2d869..ad1276f 100644 --- a/src/style.rs +++ b/src/style.rs @@ -72,7 +72,7 @@ impl Styles { } let res: Vec = STYLES - .into_iter() + .iter() .filter(|&&(ref mask, _)| (0 != (u & mask))) .map(|&(_, value)| value) .collect(); @@ -86,7 +86,7 @@ impl Styles { impl Style { pub fn to_str(self) -> String { - let styles = Styles::from_u8(self.0).unwrap_or(Vec::new()); + let styles = Styles::from_u8(self.0).unwrap_or_default(); styles .iter() .map(|s| s.to_str()) @@ -114,7 +114,6 @@ mod tests { fn empty_is_none() { assert_eq!(None, Styles::from_u8(CLEARV)) } - } mod u8_to_styles_isomorphism { @@ -270,6 +269,5 @@ mod tests { ]; test_combine!(s) } - } }