Skip to content

Commit 351c668

Browse files
committed
style(pricing): collapse the nested modality check
clippy::collapsible_if. Rewriting the two checks as slice patterns reads better than collapsing the condition and drops the redundant emptiness tests.
1 parent 42e9edc commit 351c668

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

‎rust/crates/ccusage-core/src/pricing.rs‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,18 @@ impl ModelsDevCatalogRules {
179179
let Some(modalities) = modalities else {
180180
return true;
181181
};
182-
if let Some(output) = modalities.output.as_deref() {
183-
if !output.is_empty() && !(output.len() == 1 && output[0] == "text") {
184-
return false;
185-
}
186-
}
187-
match modalities.input.as_deref() {
188-
Some(input) if !input.is_empty() => input.iter().any(|modality| modality == "text"),
189-
_ => true,
190-
}
182+
// An absent or empty list says nothing about the model, so it reads as
183+
// plain text rather than disqualifying the entry.
184+
let text_only_output = match modalities.output.as_deref() {
185+
Some([single]) => single == "text",
186+
Some([]) | None => true,
187+
Some(_) => false,
188+
};
189+
let accepts_text = match modalities.input.as_deref() {
190+
Some([]) | None => true,
191+
Some(input) => input.iter().any(|modality| modality == "text"),
192+
};
193+
text_only_output && accepts_text
191194
}
192195
}
193196

0 commit comments

Comments
 (0)