avoid matching on as_slice() when you can use is_empty()

This commit is contained in:
kevin zhao
2025-11-12 20:00:12 -05:00
parent b038bd71f9
commit 556510f378

View File

@@ -139,11 +139,10 @@ fn parse_string_example(raw: &str) -> Result<Vec<String>> {
Error::InvalidExample("example string has invalid shell syntax".to_string())
})?;
match tokens.as_slice() {
[] => Err(Error::InvalidExample(
"example cannot be an empty string".to_string(),
)),
_ => Ok(tokens),
if tokens.is_empty() {
Err(Error::InvalidExample("example cannot be an empty string".to_string()))
} else {
Ok(tokens)
}
}
@@ -164,11 +163,10 @@ fn parse_list_example(list: &ListRef) -> Result<Vec<String>> {
})
.collect::<Result<_>>()?;
match tokens.as_slice() {
[] => Err(Error::InvalidExample(
"example cannot be an empty list".to_string(),
)),
_ => Ok(tokens),
if tokens.is_empty() {
Err(Error::InvalidExample("example cannot be an empty list".to_string()))
} else {
Ok(tokens)
}
}