Skip to content

Commit

Permalink
ref(chunks): Make render_detail take Option<&str>
Browse files Browse the repository at this point in the history
Previously, this function took as its first argument an `&Option<String>`. `Option<&str>` is typically preferred over this. This change also allows us to simplify the logic for computing the detail string.
  • Loading branch information
szokeasaurusrex committed Dec 17, 2024
1 parent 3a8b380 commit 0c48e66
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/utils/chunks/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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<String>, 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.unwrap_or_else(|| fallback.unwrap_or_default());

for line in string.lines() {
if !line.is_empty() {
Expand Down

0 comments on commit 0c48e66

Please sign in to comment.