diff options
Diffstat (limited to 'dev_tools/src/bin')
| -rw-r--r-- | dev_tools/src/bin/ci.rs | 16 | ||||
| -rw-r--r-- | dev_tools/src/bin/docsify-sidebar-gen.rs | 16 | ||||
| -rw-r--r-- | dev_tools/src/bin/refresh-docs.rs | 8 | ||||
| -rw-r--r-- | dev_tools/src/bin/refresh-feature-mod.rs | 2 | ||||
| -rw-r--r-- | dev_tools/src/bin/test-examples.rs | 4 |
5 files changed, 25 insertions, 21 deletions
diff --git a/dev_tools/src/bin/ci.rs b/dev_tools/src/bin/ci.rs index 3169b95..86b930c 100644 --- a/dev_tools/src/bin/ci.rs +++ b/dev_tools/src/bin/ci.rs @@ -1,4 +1,4 @@ -use std::io::Write; +use std::io::Write as _; use std::process::exit; use tools::{cargo_tomls, eprintln_cargo_style, println_cargo_style, run_cmd}; @@ -26,7 +26,7 @@ fn main() { } if let Err(exit_code) = ci() { - restore_workspace().unwrap(); + restore_workspace(needs_commit_temp).unwrap(); exit(exit_code) } @@ -39,7 +39,7 @@ fn main() { let _ = run_cmd!("git status"); if needs_commit_temp { - restore_workspace().unwrap(); + restore_workspace(true).unwrap(); } exit(1) } @@ -47,14 +47,16 @@ fn main() { println_cargo_style!("Done: All check passed!"); if needs_commit_temp { - restore_workspace().unwrap(); + restore_workspace(true).unwrap(); } } -fn restore_workspace() -> Result<(), i32> { +fn restore_workspace(undo_commit: bool) -> Result<(), i32> { run_cmd!("git reset --hard --quiet")?; - run_cmd!("git reset --soft HEAD~1 --quiet")?; - run_cmd!("git reset --quiet")?; + if undo_commit { + run_cmd!("git reset --soft HEAD~1 --quiet")?; + run_cmd!("git reset --quiet")?; + } Ok(()) } diff --git a/dev_tools/src/bin/docsify-sidebar-gen.rs b/dev_tools/src/bin/docsify-sidebar-gen.rs index e0f9370..ccd2641 100644 --- a/dev_tools/src/bin/docsify-sidebar-gen.rs +++ b/dev_tools/src/bin/docsify-sidebar-gen.rs @@ -1,4 +1,5 @@ use std::collections::BTreeMap; +use std::fmt::Write; use std::path::Path; use tools::println_cargo_style; @@ -56,7 +57,7 @@ fn gen_translation_sidebars() { } } -/// Build sidebar content: scan .md files in pages_dir and return a formatted sidebar string +/// Build sidebar content: scan .md files in `pages_dir` and return a formatted sidebar string fn build_sidebar_content(base_dir: &Path, pages_dir: &Path, sidebar_head: &str) -> String { let mut lines = String::from(sidebar_head); @@ -95,7 +96,7 @@ fn build_sidebar_content(base_dir: &Path, pages_dir: &Path, sidebar_head: &str) // Append root-level files for f in &root_files { - lines.push_str(&format!("* [{}]({})\n", f.title, f.link)); + let _ = writeln!(lines, "* [{}]({})", f.title, f.link); } // Append subdirectory groups @@ -104,9 +105,9 @@ fn build_sidebar_content(base_dir: &Path, pages_dir: &Path, sidebar_head: &str) sorted_entries.sort_by(|a, b| a.link.cmp(&b.link)); // Directory header with 2-space indent - lines.push_str(&format!("* {}\n", dir_name)); + let _ = writeln!(lines, "* {dir_name}"); for f in &sorted_entries { - lines.push_str(&format!(" * [{}]({})\n", f.title, f.link)); + let _ = writeln!(lines, " * [{}]({})", f.title, f.link); } } @@ -160,9 +161,10 @@ fn extract_title(path: &Path) -> String { } } // Fallback: use file stem - path.file_stem() - .map(|s| s.to_string_lossy().to_string()) - .unwrap_or_else(|| "Untitled".to_string()) + path.file_stem().map_or_else( + || "Untitled".to_string(), + |s| s.to_string_lossy().to_string(), + ) } fn find_git_repo() -> Option<std::path::PathBuf> { diff --git a/dev_tools/src/bin/refresh-docs.rs b/dev_tools/src/bin/refresh-docs.rs index ffa80a2..71143d1 100644 --- a/dev_tools/src/bin/refresh-docs.rs +++ b/dev_tools/src/bin/refresh-docs.rs @@ -49,7 +49,7 @@ fn gen_example_doc_module() { let template_str = template.to_string(); let template_str = template_str .lines() - .map(|line| line.trim_end()) + .map(str::trim_end) .collect::<Vec<_>>() .join("\n") + "\n"; @@ -91,19 +91,19 @@ impl ExampleContent { let cargo_toml = cargo_toml .lines() - .map(|line| format!("/// {}", line)) + .map(|line| format!("/// {line}")) .collect::<Vec<_>>() .join("\n"); let header = header .lines() - .map(|line| format!("/// {}", line)) + .map(|line| format!("/// {line}")) .collect::<Vec<_>>() .join("\n"); let code = code .lines() - .map(|line| format!("/// {}", line)) + .map(|line| format!("/// {line}")) .collect::<Vec<_>>() .join("\n"); diff --git a/dev_tools/src/bin/refresh-feature-mod.rs b/dev_tools/src/bin/refresh-feature-mod.rs index 6265e15..2255dbc 100644 --- a/dev_tools/src/bin/refresh-feature-mod.rs +++ b/dev_tools/src/bin/refresh-feature-mod.rs @@ -41,7 +41,7 @@ fn gen_feature_module() { let template_str = template.to_string(); let template_str = template_str .lines() - .map(|line| line.trim_end()) + .map(str::trim_end) .collect::<Vec<_>>() .join("\n") + "\n"; diff --git a/dev_tools/src/bin/test-examples.rs b/dev_tools/src/bin/test-examples.rs index 21abaef..ddf5f7c 100644 --- a/dev_tools/src/bin/test-examples.rs +++ b/dev_tools/src/bin/test-examples.rs @@ -75,7 +75,7 @@ fn run_all_tests(config: &TestConfig) -> (usize, usize) { /// Build the example binary, return true on success fn build_example(example_name: &str) -> bool { - let manifest = format!("examples/{}/Cargo.toml", example_name); + let manifest = format!("examples/{example_name}/Cargo.toml"); run_cmd!("cargo build --manifest-path {}", manifest).is_ok() } @@ -132,7 +132,7 @@ fn run_single_test(example_name: &str, test_case: &TestCase) -> bool { fn get_binary_name(example_name: &str) -> String { let base = example_name; if cfg!(target_os = "windows") { - format!("{}.exe", base) + format!("{base}.exe") } else { base.to_string() } |
