From 27c7296b7577bdfffa110adf0a0fff505ea6c94a Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Mon, 16 Dec 2024 17:26:33 +0100 Subject: [PATCH] ref(chunks): Make `render_detail` take `Option<&str>` Previously, this function took as its first argument an `&Option`. `Option<&str>` is typically preferred over this. This change also allows us to simplify the logic for computing the detail string. Co-authored-by: Sebastian Zivota --- src/utils/chunks/upload.rs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/utils/chunks/upload.rs b/src/utils/chunks/upload.rs index 7f7a294ac8..60e0176db1 100644 --- a/src/utils/chunks/upload.rs +++ b/src/utils/chunks/upload.rs @@ -271,7 +271,7 @@ where dif.data.kind.map(|c| format!(" {c:#}")).unwrap_or_default() ); - render_detail(&success.detail, None); + render_detail(success.detail.as_deref(), None); } else if let Some(object) = objects_by_checksum.get(&checksum) { // If we skip waiting for the server to finish processing, there // are pending entries. We only expect results that have been @@ -300,7 +300,7 @@ where }; println!(" {:>7} {}", console::style("ERROR").red(), object.name()); - render_detail(&error.detail, fallback); + render_detail(error.detail.as_deref(), fallback); } // Return only successful uploads @@ -312,17 +312,8 @@ where /// Renders the given detail string to the command line. If the `detail` is /// either missing or empty, the optional fallback will be used. -fn render_detail(detail: &Option, fallback: Option<&str>) { - let mut string = match *detail { - Some(ref string) => string.as_str(), - None => "", - }; - - if string.is_empty() { - if let Some(fallback) = fallback { - string = fallback; - } - } +fn render_detail(detail: Option<&str>, fallback: Option<&str>) { + let string = detail.or(fallback).unwrap_or_default(); for line in string.lines() { if !line.is_empty() {