diff --git a/src/app.rs b/src/app.rs index cb902530..c0d0db9e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -776,19 +776,21 @@ impl App { } Action::DeleteBranch(branch_ref, false) => { self.queue.push( - if let Some(name) = branch_ref.rsplit('/').next() - { - InternalEvent::Push( - name.to_string(), - false, - true, - ) - } else { - InternalEvent::ShowErrorMsg(format!( - "Failed to find the branch name in {}", - branch_ref - )) - }, + branch_ref.rsplit('/').next().map_or_else( + || { + InternalEvent::ShowErrorMsg(format!( + "Failed to find the branch name in {}", + branch_ref + )) + }, + |name| { + InternalEvent::Push( + name.to_string(), + false, + true, + ) + }, + ), ); flags.insert(NeedsUpdate::ALL); self.select_branch_popup.update_branches()?; diff --git a/src/components/blame_file.rs b/src/components/blame_file.rs index 2c26b167..8f12e95f 100644 --- a/src/components/blame_file.rs +++ b/src/components/blame_file.rs @@ -354,23 +354,23 @@ impl BlameFileComponent { /// fn get_rows(&self, width: usize) -> Vec { - if let Some(ref file_blame) = self.file_blame { - file_blame - .lines - .iter() - .enumerate() - .map(|(i, (blame_hunk, line))| { - self.get_line_blame( - width, - i, - (blame_hunk.as_ref(), line.as_ref()), - file_blame, - ) - }) - .collect() - } else { - vec![] - } + self.file_blame + .as_ref() + .map_or_else(Vec::new, |file_blame| { + file_blame + .lines + .iter() + .enumerate() + .map(|(i, (blame_hunk, line))| { + self.get_line_blame( + width, + i, + (blame_hunk.as_ref(), line.as_ref()), + file_blame, + ) + }) + .collect() + }) } fn get_line_blame( diff --git a/src/components/commit_details/details.rs b/src/components/commit_details/details.rs index a48e42c4..d1afdfb2 100644 --- a/src/components/commit_details/details.rs +++ b/src/components/commit_details/details.rs @@ -151,7 +151,7 @@ impl DetailsComponent { #[allow(unstable_name_collisions, clippy::too_many_lines)] fn get_text_info(&self) -> Vec { - if let Some(ref data) = self.data { + self.data.as_ref().map_or_else(Vec::new, |data| { let mut res = vec![ Spans::from(vec![ style_detail(&self.theme, &Detail::Author), @@ -235,9 +235,7 @@ impl DetailsComponent { } res - } else { - vec![] - } + }) } fn move_scroll_top(&mut self, move_type: ScrollType) -> bool { diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs index 07859067..cd7093b6 100644 --- a/src/components/commitlist.rs +++ b/src/components/commitlist.rs @@ -286,11 +286,10 @@ impl CommitList { // commit tags txt.push(Span::styled( - Cow::from(if let Some(tags) = tags { - format!(" {}", tags) - } else { - String::from("") - }), + Cow::from(tags.map_or_else( + || String::from(""), + |tags| format!(" {}", tags), + )), theme.tags(selected), )); diff --git a/src/components/taglist.rs b/src/components/taglist.rs index ffa693a2..fd7f8730 100644 --- a/src/components/taglist.rs +++ b/src/components/taglist.rs @@ -368,11 +368,9 @@ impl TagListComponent { /// fn get_rows(&self) -> Vec { - if let Some(ref tags) = self.tags { + self.tags.as_ref().map_or_else(Vec::new, |tags| { tags.iter().map(|tag| self.get_row(tag)).collect() - } else { - vec![] - } + }) } /// diff --git a/src/tabs/status.rs b/src/tabs/status.rs index 8dcaeccb..517a68b1 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -181,15 +181,16 @@ impl Status { chunks: &[tui::layout::Rect], ) { if let Some(branch_name) = self.git_branch_name.last() { - let ahead_behind = - if let Some(state) = &self.git_branch_state { + let ahead_behind = self + .git_branch_state + .as_ref() + .map_or_else(String::new, |state| { format!( "\u{2191}{} \u{2193}{} ", state.ahead, state.behind, ) - } else { - String::new() - }; + }); + let w = Paragraph::new(format!( "{}{{{}}}", ahead_behind, branch_name