Skip to content

Fixed some clippy warnings and errors #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,16 @@ impl ColoredString {
// TODO: BoyScoutRule
let reset = "\x1B[0m";
let style = self.compute_style();
let matches: Vec<usize> = self.input
let matches: Vec<usize> = 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();
Expand All @@ -191,8 +191,6 @@ impl ColoredString {
input.insert(offset, cchar);
offset += 1;
}

idx_in_matches += 1;
}

input
Expand Down
6 changes: 2 additions & 4 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Styles {
}

let res: Vec<Styles> = STYLES
.into_iter()
.iter()
.filter(|&&(ref mask, _)| (0 != (u & mask)))
.map(|&(_, value)| value)
.collect();
Expand All @@ -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())
Expand Down Expand Up @@ -114,7 +114,6 @@ mod tests {
fn empty_is_none() {
assert_eq!(None, Styles::from_u8(CLEARV))
}

}

mod u8_to_styles_isomorphism {
Expand Down Expand Up @@ -270,6 +269,5 @@ mod tests {
];
test_combine!(s)
}

}
}