Skip to content

Commit 5471957

Browse files
committed
small fix to is_crate()
1 parent ca0d879 commit 5471957

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

cargo-typify/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ impl std::str::FromStr for CrateSpec {
100100

101101
fn from_str(s: &str) -> Result<Self, Self::Err> {
102102
fn is_crate(s: &str) -> bool {
103-
!s.contains(|cc: char| !cc.is_alphabetic() && cc != '-' && cc != '_')
103+
s.starts_with(|cc: char| cc.is_alphabetic() || cc == '_')
104+
&& !s.contains(|cc: char| !cc.is_alphanumeric() && cc != '-' && cc != '_')
104105
}
105106

106107
fn convert(s: &str) -> Option<CrateSpec> {

typify-macro/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ impl<'de> Deserialize<'de> for CrateName {
159159
}
160160

161161
fn is_crate(s: &str) -> bool {
162-
!s.contains(|cc: char| !cc.is_alphanumeric() && cc != '_' && cc != '-')
162+
s.starts_with(|cc: char| cc.is_alphabetic() || cc == '_')
163+
&& !s.contains(|cc: char| !cc.is_alphanumeric() && cc != '_' && cc != '-')
163164
}
164165

165166
#[derive(Deserialize)]

0 commit comments

Comments
 (0)