summaryrefslogtreecommitdiff
path: root/gen/src/env.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-03-20 22:21:56 +0800
committer魏曹先生 <1992414357@qq.com>2026-03-20 22:21:56 +0800
commitab6be7968b25afb57fc428695693484ad8576718 (patch)
treee4af27964f195a18a678844dbe71c0aaa182b5dc /gen/src/env.rs
parent6b22f7b7694fce530f84ba94c65c057450cca626 (diff)
Refactor code to use modern Rust idioms and fix clippy lints
Diffstat (limited to 'gen/src/env.rs')
-rw-r--r--gen/src/env.rs33
1 files changed, 12 insertions, 21 deletions
diff --git a/gen/src/env.rs b/gen/src/env.rs
index c45830e..c622fba 100644
--- a/gen/src/env.rs
+++ b/gen/src/env.rs
@@ -5,17 +5,13 @@ pub fn get_author() -> Result<String, Box<dyn std::error::Error>> {
let cargo_toml_content = std::fs::read_to_string(cargo_toml_path)?;
let cargo_toml: toml::Value = toml::from_str(&cargo_toml_content)?;
- if let Some(package) = cargo_toml.get("package") {
- if let Some(authors) = package.get("authors") {
- if let Some(authors_array) = authors.as_array() {
- if let Some(first_author) = authors_array.get(0) {
- if let Some(author_str) = first_author.as_str() {
+ if let Some(package) = cargo_toml.get("package")
+ && let Some(authors) = package.get("authors")
+ && let Some(authors_array) = authors.as_array()
+ && let Some(first_author) = authors_array.first()
+ && let Some(author_str) = first_author.as_str() {
return Ok(author_str.to_string());
}
- }
- }
- }
- }
Err("Author not found in Cargo.toml".into())
}
@@ -25,13 +21,11 @@ pub fn get_site() -> Result<String, Box<dyn std::error::Error>> {
let cargo_toml_content = std::fs::read_to_string(cargo_toml_path)?;
let cargo_toml: toml::Value = toml::from_str(&cargo_toml_content)?;
- if let Some(package) = cargo_toml.get("package") {
- if let Some(homepage) = package.get("homepage") {
- if let Some(site_str) = homepage.as_str() {
+ if let Some(package) = cargo_toml.get("package")
+ && let Some(homepage) = package.get("homepage")
+ && let Some(site_str) = homepage.as_str() {
return Ok(site_str.to_string());
}
- }
- }
Err("Homepage not found in Cargo.toml".into())
}
@@ -85,15 +79,12 @@ pub fn get_version() -> String {
Err(_) => return "unknown".to_string(),
};
- if let Some(workspace) = cargo_toml.get("workspace") {
- if let Some(package) = workspace.get("package") {
- if let Some(version) = package.get("version") {
- if let Some(version_str) = version.as_str() {
+ if let Some(workspace) = cargo_toml.get("workspace")
+ && let Some(package) = workspace.get("package")
+ && let Some(version) = package.get("version")
+ && let Some(version_str) = version.as_str() {
return version_str.to_string();
}
- }
- }
- }
"unknown".to_string()
}