Skip to content

Commit

Permalink
[Clippy] Miscellaneous fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJuliusMartinez committed Feb 9, 2022
1 parent 2a53257 commit 931adff
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl App {

fn buffer_input(&mut self, ch: u8) {
// Don't buffer leading 0s.
if self.input_buffer.is_empty() && ch == '0' as u8 {
if self.input_buffer.is_empty() && ch == b'0' {
return;
}

Expand All @@ -391,7 +391,7 @@ impl App {
Some(Action::MoveFocusedLineToCenter)
} else {
self.input_buffer.clear();
self.buffer_input('z' as u8);
self.buffer_input(b'z');
None
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ impl Iterator for TuiInput {
};
}

if poll_res.is_some() {
return Some(Err(poll_res.unwrap()));
if let Some(poll_err) = poll_res {
return Some(Err(poll_err));
}

if self.poll_fds[SIGWINCH_PIPE_INDEX].revents & libc::POLLIN != 0 {
Expand Down
7 changes: 3 additions & 4 deletions src/jsonparser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl<'a> JsonParser<'a> {
self.pretty_printed.push_str(", ");
} else {
// Add space inside objects.
self.pretty_printed.push_str(" ");
self.pretty_printed.push(' ');
}

if self.peek_token()? != JsonToken::String {
Expand Down Expand Up @@ -338,7 +338,7 @@ impl<'a> JsonParser<'a> {
self.rows[object_open_index].range.end = self.rows[object_open_index].range.start + 2;
} else {
// Print space inside closing brace.
self.pretty_printed.push_str(" ");
self.pretty_printed.push(' ');

let close_value = Value::CloseContainer {
container_type: ContainerType::Object,
Expand Down Expand Up @@ -383,8 +383,7 @@ impl<'a> JsonParser<'a> {
let (bool_str, len) = if b { ("true", 4) } else { ("false", 5) };

self.rows[row_index].range.end = self.rows[row_index].range.start + len;
self.pretty_printed
.push_str(if b { bool_str } else { bool_str });
self.pretty_printed.push_str(bool_str);

Ok(row_index)
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fn print_pretty_printed_json(json: String) {
if trailing_comma {
print!(",");
}
println!("");
println!();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/screenwriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl ScreenWriter {
result
}

fn print_line<'a>(
fn print_line(
&mut self,
viewer: &JsonViewer,
screen_index: u16,
Expand Down
12 changes: 6 additions & 6 deletions src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ impl SearchState {
let regex_input;
let mut case_sensitive_specified = false;

if search_input.ends_with("/") {
regex_input = &search_input[..search_input.len() - 1];
} else if search_input.ends_with("/s") {
regex_input = &search_input[..search_input.len() - 2];
if let Some(stripped_of_slash) = search_input.strip_suffix('/') {
regex_input = stripped_of_slash;
} else if let Some(stripped_of_slash_s) = search_input.strip_suffix("/s") {
regex_input = stripped_of_slash_s;
case_sensitive_specified = true;
} else {
regex_input = search_input;
Expand Down Expand Up @@ -307,7 +307,7 @@ impl SearchState {
next_match - 1
};

self.cycle_match(next_match_index, -1 * (jumps - 1) as isize)
self.cycle_match(next_match_index, -((jumps - 1) as isize))
}
}
}
Expand All @@ -318,7 +318,7 @@ impl SearchState {
} => {
let delta: isize = match true_direction {
SearchDirection::Forward => jumps as isize,
SearchDirection::Reverse => -1 * (jumps as isize),
SearchDirection::Reverse => -(jumps as isize),
};

if last_search_into_collapsed_container {
Expand Down
14 changes: 6 additions & 8 deletions src/truncatedstrview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct RangeAdjuster<'a> {
impl TruncatedRange {
// Create a RangeAdjuster representing the current state of the
// TruncatedRange.
fn to_adjuster<'a, 'b>(&'a self, s: &'b str, available_space: isize) -> RangeAdjuster<'b> {
fn adjuster<'a, 'b>(&'a self, s: &'b str, available_space: isize) -> RangeAdjuster<'b> {
let mut used_space = self.used_space;
// The adjuster doesn't keep track of the replacement character.
if self.showing_replacement_character {
Expand Down Expand Up @@ -183,10 +183,8 @@ impl TruncatedStrView {
/// Return the amount of space used by a string view, if the string
/// is representable.
pub fn used_space(&self) -> Option<isize> {
match self.range {
None => None,
Some(TruncatedRange { used_space, .. }) => Some(used_space),
}
self.range
.map(|TruncatedRange { used_space, .. }| used_space)
}

/// Check whether this is a view of a string that is totally elided,
Expand All @@ -206,7 +204,7 @@ impl TruncatedStrView {
// is representable and we have a view.
fn range_adjuster<'a, 'b>(&'a self, s: &'b str) -> RangeAdjuster<'b> {
debug_assert!(self.range.is_some());
self.range.unwrap().to_adjuster(s, self.available_space)
self.range.unwrap().adjuster(s, self.available_space)
}

/// Scrolls a string view to the right by at least the specified
Expand Down Expand Up @@ -488,14 +486,14 @@ impl<'a> RangeAdjuster<'a> {
/// Add as many characters to the right side of the string as we
/// can without exceeding the available space.
pub fn fill_right(&mut self) {
let mut right_graphemes = self.s[self.end..].graphemes(true);
let right_graphemes = self.s[self.end..].graphemes(true);
// Note that we should consider the next grapheme even if we
// have already used up all the available space, because the
// next grapheme might be the end of the string, and we'd no
// longer have to show the ellipsis.
//
// This allows converting "…xy…" to "…xyz".
while let Some(grapheme) = right_graphemes.next() {
for grapheme in right_graphemes {
if !self.add_grapheme_to_right_if_it_will_fit(grapheme) {
break;
}
Expand Down

0 comments on commit 931adff

Please sign in to comment.