Skip to content

Commit 0c2432e

Browse files
committed
fix(scanner): implement FromStr for Language to resolve clippy error
1 parent e8d07a3 commit 0c2432e

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

crates/scanner/src/language.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Supported programming languages.
22
33
use serde::{Deserialize, Serialize};
4+
use std::str::FromStr;
45

56
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
67
#[serde(rename_all = "snake_case")]
@@ -41,10 +42,13 @@ impl Language {
4142
_ => Self::Unknown,
4243
}
4344
}
45+
}
46+
47+
impl FromStr for Language {
48+
type Err = std::convert::Infallible;
4449

45-
/// Detect language from a string (e.g. from an API request).
46-
pub fn from_str(s: &str) -> Self {
47-
match s.to_lowercase().as_str() {
50+
fn from_str(s: &str) -> Result<Self, Self::Err> {
51+
Ok(match s.to_lowercase().as_str() {
4852
"python" | "py" => Self::Python,
4953
"javascript" | "js" => Self::JavaScript,
5054
"typescript" | "ts" => Self::TypeScript,
@@ -59,6 +63,6 @@ impl Language {
5963
"swift" => Self::Swift,
6064
"kotlin" | "kt" => Self::Kotlin,
6165
_ => Self::Unknown,
62-
}
66+
})
6367
}
6468
}

crates/server/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async fn run_scan(
6868

6969
let config = ScanConfig {
7070
code: payload.code,
71-
language: Language::from_str(&payload.language),
71+
language: payload.language.parse().unwrap_or(Language::Unknown),
7272
engines,
7373
ai_config: payload.ai_config,
7474
file_path: None,

0 commit comments

Comments
 (0)