Skip to content

Commit bfaf988

Browse files
authored
Eliminate unwrap from Keyword::valid_name (#5043)
1 parent 3e5f0b4 commit bfaf988

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/models/keyword.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,13 @@ impl Keyword {
5050
}
5151

5252
pub fn valid_name(name: &str) -> bool {
53-
if name.is_empty() {
54-
return false;
55-
}
56-
// unwrap is okay because name is non-empty
57-
name.chars().next().unwrap().is_ascii_alphanumeric()
58-
&& name
59-
.chars()
60-
.all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '-')
53+
let mut chars = name.chars();
54+
let first = match chars.next() {
55+
None => return false,
56+
Some(c) => c,
57+
};
58+
first.is_ascii_alphanumeric()
59+
&& chars.all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '-')
6160
}
6261

6362
pub fn update_crate(conn: &PgConnection, krate: &Crate, keywords: &[&str]) -> QueryResult<()> {

0 commit comments

Comments
 (0)