From 9846bf6c7f28c916e4619bb0b31c50bb284171e1 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Fri, 20 Jan 2023 16:19:07 +0100 Subject: [PATCH] style: use bool::then() --- lib/src/git.rs | 7 ++----- lib/src/index.rs | 6 +----- lib/src/working_copy.rs | 6 +----- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/lib/src/git.rs b/lib/src/git.rs index caec39eb5..184c003c0 100644 --- a/lib/src/git.rs +++ b/lib/src/git.rs @@ -553,11 +553,8 @@ impl<'a> RemoteCallbacks<'a> { if let Some(progress_cb) = self.progress { callbacks.transfer_progress(move |progress| { progress_cb(&Progress { - bytes_downloaded: if progress.received_objects() < progress.total_objects() { - Some(progress.received_bytes() as u64) - } else { - None - }, + bytes_downloaded: (progress.received_objects() < progress.total_objects()) + .then(|| progress.received_bytes() as u64), overall: (progress.indexed_objects() + progress.indexed_deltas()) as f32 / (progress.total_objects() + progress.total_deltas()) as f32, }); diff --git a/lib/src/index.rs b/lib/src/index.rs index ce4119228..3cc655251 100644 --- a/lib/src/index.rs +++ b/lib/src/index.rs @@ -1240,11 +1240,7 @@ impl IndexSegment for ReadonlyIndex { fn segment_commit_id_to_pos(&self, commit_id: &CommitId) -> Option { let lookup_pos = self.commit_id_byte_prefix_to_lookup_pos(commit_id)?; let entry = self.lookup_entry(lookup_pos); - if &entry.commit_id() == commit_id { - Some(entry.pos()) - } else { - None - } + (&entry.commit_id() == commit_id).then(|| entry.pos()) } fn segment_resolve_prefix(&self, prefix: &HexPrefix) -> PrefixResolution { diff --git a/lib/src/working_copy.rs b/lib/src/working_copy.rs index 71f9ad0f1..6d0c93fb3 100644 --- a/lib/src/working_copy.rs +++ b/lib/src/working_copy.rs @@ -495,11 +495,7 @@ impl TreeState { .file_states .iter() .filter_map(|(path, state)| { - if state.file_type != FileType::GitSubmodule { - Some(path.clone()) - } else { - None - } + (state.file_type != FileType::GitSubmodule).then(|| path.clone()) }) .collect(); while let Some((dir, disk_dir, git_ignore)) = work.pop() {