summaryrefslogtreecommitdiff
path: root/gen/src/gen_override_renderer.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/gen_override_renderer.rs
parent6b22f7b7694fce530f84ba94c65c057450cca626 (diff)
Refactor code to use modern Rust idioms and fix clippy lints
Diffstat (limited to 'gen/src/gen_override_renderer.rs')
-rw-r--r--gen/src/gen_override_renderer.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/gen/src/gen_override_renderer.rs b/gen/src/gen_override_renderer.rs
index cb78e01..7ed0f86 100644
--- a/gen/src/gen_override_renderer.rs
+++ b/gen/src/gen_override_renderer.rs
@@ -1,4 +1,7 @@
-use std::{collections::HashSet, path::PathBuf};
+use std::{
+ collections::HashSet,
+ path::{Path, PathBuf},
+};
use just_template::{Template, tmpl};
use regex::Regex;
@@ -12,7 +15,7 @@ use crate::{
resolve_types::resolve_type_paths,
};
-pub async fn generate_override_renderer(repo_root: &PathBuf) {
+pub async fn generate_override_renderer(repo_root: &Path) {
let template_path = repo_root.join(OVERRIDE_RENDERER_ENTRY_TEMPLATE);
let output_path = repo_root.join(OVERRIDE_RENDERER_ENTRY);
let all_possible_types = collect_all_possible_types(&PathBuf::from(COMMANDS_PATH)).await;
@@ -45,7 +48,7 @@ pub async fn generate_override_renderer(repo_root: &PathBuf) {
}
/// Generate override renderers list file from Registry.toml configuration using just_template
-pub async fn generate_override_renderers_list(repo_root: &PathBuf) {
+pub async fn generate_override_renderers_list(repo_root: &Path) {
let template_path = repo_root.join(OVERRIDE_RENDERERS_TEMPLATE);
let output_path = repo_root.join(OVERRIDE_RENDERERS);
let config_path = repo_root.join(REGISTRY_TOML);
@@ -103,9 +106,9 @@ pub async fn generate_override_renderers_list(repo_root: &PathBuf) {
);
}
-pub async fn collect_all_possible_types(dir: &PathBuf) -> HashSet<String> {
+pub async fn collect_all_possible_types(dir: &Path) -> HashSet<String> {
let mut all_types = HashSet::new();
- let mut dirs_to_visit = vec![dir.clone()];
+ let mut dirs_to_visit = vec![dir.to_path_buf()];
while let Some(current_dir) = dirs_to_visit.pop() {
let entries_result = fs::read_dir(&current_dir).await;
@@ -130,7 +133,7 @@ pub async fn collect_all_possible_types(dir: &PathBuf) -> HashSet<String> {
let path = entry.path();
if path.is_dir() {
- dirs_to_visit.push(path);
+ dirs_to_visit.push(path.to_path_buf());
continue;
}
@@ -159,7 +162,7 @@ pub async fn collect_all_possible_types(dir: &PathBuf) -> HashSet<String> {
all_types
}
-pub fn get_output_types(code: &String) -> Option<Vec<String>> {
+pub fn get_output_types(code: &str) -> Option<Vec<String>> {
let mut output_types = Vec::new();
// Find all cmd_output! macros