Skip to content

Commit 12b596f

Browse files
geofflittleclaude
andcommitted
refactor: replace SanitizeMode::from_str with From<&str> impl
Address Gemini review feedback: use idiomatic From trait instead of a custom from_str method, which also removes the clippy should_implement_trait allow. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ac9eaa3 commit 12b596f

3 files changed

Lines changed: 12 additions & 13 deletions

File tree

src/helpers/modelarmor.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -377,23 +377,23 @@ mod tests {
377377

378378
#[test]
379379
fn test_sanitize_mode_from_str_warn() {
380-
assert_eq!(SanitizeMode::from_str("warn"), SanitizeMode::Warn);
381-
assert_eq!(SanitizeMode::from_str("WARN"), SanitizeMode::Warn);
382-
assert_eq!(SanitizeMode::from_str("Warn"), SanitizeMode::Warn);
380+
assert_eq!(SanitizeMode::from("warn"), SanitizeMode::Warn);
381+
assert_eq!(SanitizeMode::from("WARN"), SanitizeMode::Warn);
382+
assert_eq!(SanitizeMode::from("Warn"), SanitizeMode::Warn);
383383
}
384384

385385
#[test]
386386
fn test_sanitize_mode_from_str_block() {
387-
assert_eq!(SanitizeMode::from_str("block"), SanitizeMode::Block);
388-
assert_eq!(SanitizeMode::from_str("BLOCK"), SanitizeMode::Block);
389-
assert_eq!(SanitizeMode::from_str("Block"), SanitizeMode::Block);
387+
assert_eq!(SanitizeMode::from("block"), SanitizeMode::Block);
388+
assert_eq!(SanitizeMode::from("BLOCK"), SanitizeMode::Block);
389+
assert_eq!(SanitizeMode::from("Block"), SanitizeMode::Block);
390390
}
391391

392392
#[test]
393393
fn test_sanitize_mode_from_str_unknown_defaults_to_warn() {
394-
assert_eq!(SanitizeMode::from_str(""), SanitizeMode::Warn);
395-
assert_eq!(SanitizeMode::from_str("invalid"), SanitizeMode::Warn);
396-
assert_eq!(SanitizeMode::from_str("stop"), SanitizeMode::Warn);
394+
assert_eq!(SanitizeMode::from(""), SanitizeMode::Warn);
395+
assert_eq!(SanitizeMode::from("invalid"), SanitizeMode::Warn);
396+
assert_eq!(SanitizeMode::from("stop"), SanitizeMode::Warn);
397397
}
398398

399399
#[test]

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ async fn run() -> Result<(), GwsError> {
201201
.or_else(|| std::env::var("GOOGLE_WORKSPACE_CLI_SANITIZE_TEMPLATE").ok());
202202

203203
let sanitize_mode = std::env::var("GOOGLE_WORKSPACE_CLI_SANITIZE_MODE")
204-
.map(|v| helpers::modelarmor::SanitizeMode::from_str(&v))
204+
.map(|v| helpers::modelarmor::SanitizeMode::from(v.as_str()))
205205
.unwrap_or(helpers::modelarmor::SanitizeMode::Warn);
206206

207207
let sanitize_config = parse_sanitize_config(sanitize_template, &sanitize_mode)?;

src/sanitize.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,12 @@ impl Default for SanitizeConfig {
6565
}
6666
}
6767

68-
impl SanitizeMode {
68+
impl From<&str> for SanitizeMode {
6969
/// Parses a string into a `SanitizeMode`.
7070
///
7171
/// * "block" (case-insensitive) -> `Block`
7272
/// * Any other value -> `Warn` (safe default)
73-
#[allow(clippy::should_implement_trait)]
74-
pub fn from_str(s: &str) -> Self {
73+
fn from(s: &str) -> Self {
7574
match s.to_lowercase().as_str() {
7675
"block" => SanitizeMode::Block,
7776
_ => SanitizeMode::Warn,

0 commit comments

Comments
 (0)