From 668793a2ba0ffed76ca69be94effdfa772478738 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Fri, 22 Dec 2023 15:33:05 +0100 Subject: [PATCH] lib: Fix compiler warnings --- src/issue/main.rs | 1 + src/patch/main.rs | 1 + src/ui/layout.rs | 4 ++-- src/ui/state.rs | 6 ++---- src/ui/widget/context.rs | 2 +- src/ui/widget/form.rs | 10 +++++----- src/ui/widget/label.rs | 7 +++++-- 7 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/issue/main.rs b/src/issue/main.rs index d9a38f5d..9ecc1acb 100644 --- a/src/issue/main.rs +++ b/src/issue/main.rs @@ -35,6 +35,7 @@ Options struct Options; impl Options { + #[allow(clippy::never_loop)] fn from_env() -> Result { use lexopt::prelude::*; diff --git a/src/patch/main.rs b/src/patch/main.rs index 7d982054..ca3366c3 100644 --- a/src/patch/main.rs +++ b/src/patch/main.rs @@ -35,6 +35,7 @@ Options struct Options; impl Options { + #[allow(clippy::never_loop)] fn from_env() -> Result { use lexopt::prelude::*; diff --git a/src/ui/layout.rs b/src/ui/layout.rs index febccbef..681cac76 100644 --- a/src/ui/layout.rs +++ b/src/ui/layout.rs @@ -42,7 +42,7 @@ pub fn v_stack( .constraints(constraints) .split(area); - widgets.into_iter().zip(layout.into_iter()).collect() + widgets.into_iter().zip(layout).collect() } pub fn h_stack( @@ -64,7 +64,7 @@ pub fn h_stack( .constraints(constraints) .split(area); - widgets.into_iter().zip(layout.into_iter()).collect() + widgets.into_iter().zip(layout).collect() } pub fn app_header(area: Rect, info_w: u16) -> AppHeader { diff --git a/src/ui/state.rs b/src/ui/state.rs index e473841a..c269c339 100644 --- a/src/ui/state.rs +++ b/src/ui/state.rs @@ -36,9 +36,8 @@ impl ItemState { pub fn select_previous(&mut self) -> Option { let old_index = self.selected(); let new_index = match old_index { - Some(selected) if selected == 0 => Some(0), + Some(0) | None => Some(0), Some(selected) => Some(selected.saturating_sub(1)), - None => Some(0), }; if old_index != new_index { @@ -102,9 +101,8 @@ impl FormState { pub fn focus_previous(&mut self) -> Option { let old_index = self.focus(); let new_index = match old_index { - Some(focus) if focus == 0 => Some(0), + Some(0) | None => Some(0), Some(focus) => Some(focus.saturating_sub(1)), - None => Some(0), }; if old_index != new_index { diff --git a/src/ui/widget/context.rs b/src/ui/widget/context.rs index aab196fa..6d743b9d 100644 --- a/src/ui/widget/context.rs +++ b/src/ui/widget/context.rs @@ -132,7 +132,7 @@ pub struct ContextBar { } impl ContextBar { - pub const PROP_EDIT_MODE: &str = "edit-mode"; + pub const PROP_EDIT_MODE: &'static str = "edit-mode"; pub fn new( theme: Theme, diff --git a/src/ui/widget/form.rs b/src/ui/widget/form.rs index f8e76389..3f64b77d 100644 --- a/src/ui/widget/form.rs +++ b/src/ui/widget/form.rs @@ -182,12 +182,12 @@ pub struct Form { } impl Form { - pub const CMD_FOCUS_PREVIOUS: &str = "cmd-focus-previous"; - pub const CMD_FOCUS_NEXT: &str = "cmd-focus-next"; - pub const CMD_NEWLINE: &str = "cmd-newline"; - pub const CMD_PASTE: &str = "cmd-paste"; + pub const CMD_FOCUS_PREVIOUS: &'static str = "cmd-focus-previous"; + pub const CMD_FOCUS_NEXT: &'static str = "cmd-focus-next"; + pub const CMD_NEWLINE: &'static str = "cmd-newline"; + pub const CMD_PASTE: &'static str = "cmd-paste"; - pub const PROP_ID: &str = "prop-id"; + pub const PROP_ID: &'static str = "prop-id"; pub fn new(_theme: Theme, inputs: Vec>) -> Self { let state = FormState::new(Some(0), inputs.len()); diff --git a/src/ui/widget/label.rs b/src/ui/widget/label.rs index 4e3d21d7..3b148712 100644 --- a/src/ui/widget/label.rs +++ b/src/ui/widget/label.rs @@ -95,7 +95,7 @@ pub struct Textarea { } impl Textarea { - pub const PROP_DISPLAY_PROGRESS: &str = "display-progress"; + pub const PROP_DISPLAY_PROGRESS: &'static str = "display-progress"; pub fn new(theme: Theme) -> Self { Self { @@ -163,7 +163,10 @@ impl WidgetComponent for Textarea { self.len = body.len(); self.height = (layout[0].height - 1) as usize; - let body: String = body.iter().map(|line| format!("{}\n", line)).collect(); + let body: String = body.iter().fold(String::new(), |mut body, line| { + body.push_str(&format!("{}\n", line)); + body + }); let paragraph = Paragraph::new(body) .scroll((self.offset as u16, 0))