From be6f824a43cf998099a6f91cecb09ca461a6094e Mon Sep 17 00:00:00 2001 From: ClementTsang Date: Mon, 6 Jul 2020 02:35:39 -0400 Subject: [PATCH] clippy: clippy error due to redundant conversion Fixes a redundant usize to usize conversion. --- Cargo.lock | 2 +- src/canvas/widgets/cpu_graph.rs | 87 +++++++++++++++------------------ 2 files changed, 41 insertions(+), 48 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 91090cd1..5f656a5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -130,7 +130,7 @@ dependencies = [ [[package]] name = "bottom" -version = "0.4.3" +version = "0.4.4" dependencies = [ "assert_cmd", "backtrace", diff --git a/src/canvas/widgets/cpu_graph.rs b/src/canvas/widgets/cpu_graph.rs index 3fcd0bef..e6800f91 100644 --- a/src/canvas/widgets/cpu_graph.rs +++ b/src/canvas/widgets/cpu_graph.rs @@ -100,8 +100,6 @@ impl CpuGraphWidget for Painter { fn draw_cpu_graph( &self, f: &mut Frame<'_, B>, app_state: &mut App, draw_loc: Rect, widget_id: u64, ) { - use std::convert::TryFrom; - if let Some(cpu_widget_state) = app_state.cpu_state.widget_states.get_mut(&widget_id) { let cpu_data: &mut [ConvertedCpuData] = &mut app_state.canvas_data.cpu_data; @@ -147,51 +145,46 @@ impl CpuGraphWidget for Painter { let use_dot = app_state.app_config_fields.use_dot; let show_avg_cpu = app_state.app_config_fields.show_average_cpu; - let dataset_vector: Vec> = if let Ok(current_scroll_position) = - usize::try_from(cpu_widget_state.scroll_state.current_scroll_position) - { - if current_scroll_position == ALL_POSITION { - cpu_data - .iter() - .enumerate() - .rev() - .map(|(itx, cpu)| { - Dataset::default() - .marker(if use_dot { - Marker::Dot - } else { - Marker::Braille - }) - .style(if show_avg_cpu && itx == AVG_POSITION { - self.colours.avg_colour_style - } else { - self.colours.cpu_colour_styles - [itx % self.colours.cpu_colour_styles.len()] - }) - .data(&cpu.cpu_data[..]) - .graph_type(tui::widgets::GraphType::Line) - }) - .collect() - } else if let Some(cpu) = cpu_data.get(current_scroll_position) { - vec![Dataset::default() - .marker(if use_dot { - Marker::Dot - } else { - Marker::Braille - }) - .style(if show_avg_cpu && current_scroll_position == AVG_POSITION { - self.colours.avg_colour_style - } else { - self.colours.cpu_colour_styles[cpu_widget_state - .scroll_state - .current_scroll_position - % self.colours.cpu_colour_styles.len()] - }) - .data(&cpu.cpu_data[..]) - .graph_type(tui::widgets::GraphType::Line)] - } else { - vec![] - } + let current_scroll_position = cpu_widget_state.scroll_state.current_scroll_position; + let dataset_vector: Vec> = if current_scroll_position == ALL_POSITION { + cpu_data + .iter() + .enumerate() + .rev() + .map(|(itx, cpu)| { + Dataset::default() + .marker(if use_dot { + Marker::Dot + } else { + Marker::Braille + }) + .style(if show_avg_cpu && itx == AVG_POSITION { + self.colours.avg_colour_style + } else { + self.colours.cpu_colour_styles + [itx % self.colours.cpu_colour_styles.len()] + }) + .data(&cpu.cpu_data[..]) + .graph_type(tui::widgets::GraphType::Line) + }) + .collect() + } else if let Some(cpu) = cpu_data.get(current_scroll_position) { + vec![Dataset::default() + .marker(if use_dot { + Marker::Dot + } else { + Marker::Braille + }) + .style(if show_avg_cpu && current_scroll_position == AVG_POSITION { + self.colours.avg_colour_style + } else { + self.colours.cpu_colour_styles[cpu_widget_state + .scroll_state + .current_scroll_position + % self.colours.cpu_colour_styles.len()] + }) + .data(&cpu.cpu_data[..]) + .graph_type(tui::widgets::GraphType::Line)] } else { vec![] };