style: use if else instead of then_some + unwrap_or

create dedicated fn for `deleted` printing to improve lisibility an
deduplicate code.

clippy message: this method chain can be written more clearly with `if .. else ..`
help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#obfuscated_if_else
This commit is contained in:
Gwen Lg
2025-12-14 17:28:27 +01:00
parent 24e11e99ee
commit a5d047b5ae
3 changed files with 16 additions and 11 deletions
+1 -1
View File
@@ -230,7 +230,7 @@ fn print_token_info(token: &GetAdminTokenInfoResponse) {
format!("Created:\t{}", token.created.unwrap().with_timezone(&Local)),
format!(
"Validity:\t{}",
token.expired.then_some("EXPIRED").unwrap_or("valid")
if token.expired { "EXPIRED" } else { "valid" }
),
format!(
"Expiration:\t{}",
+14 -9
View File
@@ -67,11 +67,9 @@ impl Cli {
Some(BlockVersionBacklink::Object { bucket_id, key }) => {
table.push(format!(
"{}\t{:.16}{}\t{:.16}\t{}",
ver.ref_deleted.then_some("deleted").unwrap_or("active"),
if ver.ref_deleted { "deleted" } else { "active" },
ver.version_id,
ver.version_deleted
.then_some(" (deleted)")
.unwrap_or_default(),
deleted_to_str(ver.version_deleted),
bucket_id,
key
));
@@ -85,15 +83,13 @@ impl Cli {
}) => {
table.push(format!(
"{}\t{:.16}{}\t{:.16}\t{}\t{:.16}{}",
ver.ref_deleted.then_some("deleted").unwrap_or("active"),
if ver.ref_deleted { "deleted" } else { "active" },
ver.version_id,
ver.version_deleted
.then_some(" (deleted)")
.unwrap_or_default(),
deleted_to_str(ver.version_deleted),
bucket_id.as_deref().unwrap_or(""),
key.as_deref().unwrap_or(""),
upload_id,
upload_deleted.then_some(" (deleted)").unwrap_or_default(),
deleted_to_str(*upload_deleted),
));
}
None => {
@@ -167,3 +163,12 @@ impl Cli {
Ok(())
}
}
#[must_use]
const fn deleted_to_str(deleted: bool) -> &'static str {
if deleted {
" (deleted)"
} else {
""
}
}
+1 -1
View File
@@ -283,7 +283,7 @@ fn print_key_info(key: &GetKeyInfoResponse) {
table.extend([
format!(
"Validity:\t{}",
key.expired.then_some("EXPIRED").unwrap_or("valid")
if key.expired { "EXPIRED" } else { "valid" }
),
format!(
"Expiration:\t{}",