Skip to content

Commit

Permalink
nicknames_json_exists()関数のリファクタリング
Browse files Browse the repository at this point in the history
- `match`式から`if let`式に変更し、コードをよりシンプルに
- エラーハンドリングのロジックを簡潔に保ちつつ、可読性を向上
- デシリアライズ処理のパターンマッチングを最適化
  • Loading branch information
eda3 committed Mar 3, 2025
1 parent 680105d commit 759c78d
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,18 @@ pub async fn nicknames_json_exists(init_check: bool) -> Option<String> {
};

// JSON デシリアライズ試行
match serde_json::from_str::<Vec<Nicknames>>(&data_from_file) {
Ok(_) => {
println!("{}", "Successfully read 'nicknames.json' file.".green());
None
}
Err(_) => {
// nicknames.json 正当性エラー用メッセージ
let error_msg = "Error: Failed to deserialize 'nicknames.json' file.\nDownload and import the `data` folder from:\nhttps://github.com/yakiimoninja/baiken.".to_string();
if let Ok(_) = serde_json::from_str::<Vec<Nicknames>>(&data_from_file) {
println!("{}", "Successfully read 'nicknames.json' file.".green());
None
} else {
// nicknames.json 正当性エラー用メッセージ
let error_msg = "Error: Failed to deserialize 'nicknames.json' file.\nDownload and import the `data` folder from:\nhttps://github.com/yakiimoninja/baiken.".to_string();

if init_check {
println!();
panic!("{}", error_msg.red());
} else {
Some(error_msg)
}
if init_check {
println!();
panic!("{}", error_msg.red());
} else {
Some(error_msg)
}
}
}
Expand Down

0 comments on commit 759c78d

Please sign in to comment.