diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-03-07 19:37:52 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-03-07 19:37:52 +0800 |
| commit | 9e7c0fd45e169929156bdb317b10d7bb3db65f8b (patch) | |
| tree | 94c1e0e6cafe996b7b7da8dfd6e1ff1a04539cda /src/bin/butckrepo-refresh.rs | |
| parent | 22926ce29e3f8e040ec349401aeb6a77f32eae72 (diff) | |
Add callback support to chunk_stream_with and implement stream writing
Diffstat (limited to 'src/bin/butckrepo-refresh.rs')
| -rw-r--r-- | src/bin/butckrepo-refresh.rs | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/src/bin/butckrepo-refresh.rs b/src/bin/butckrepo-refresh.rs index 9184efb..2b3d841 100644 --- a/src/bin/butckrepo-refresh.rs +++ b/src/bin/butckrepo-refresh.rs @@ -19,8 +19,8 @@ async fn main() { println!("Updating policies ..."); let (mut lib_rs_template, mut cargo_toml_template) = { - let lib_rs_template_path = current_dir.join("policy/_policies/src/lib.rs.t"); - let cargo_toml_template_path = current_dir.join("policy/_policies/Cargo.toml.t"); + let lib_rs_template_path = current_dir.join(LIB_RS_TEMPLATE_PATH); + let cargo_toml_template_path = current_dir.join(CARGO_TOML_TEMPLATE_PATH); let lib_rs_content = fs::read_to_string(&lib_rs_template_path) .await @@ -65,7 +65,10 @@ async fn main() { tmpl_param!(lib_rs_template, policy_count = cargo_toml_pathes.len()); - let collect_futures = cargo_toml_pathes.iter().map(collect).collect::<Vec<_>>(); + let collect_futures = cargo_toml_pathes + .iter() + .map(|path| collect(path)) + .collect::<Vec<_>>(); for policy in futures::future::join_all(collect_futures).await { let Some(policy) = policy else { continue }; @@ -96,8 +99,12 @@ async fn main() { crate_name = policy.crate_name, stream_struct_id = stream_struct_id ) }, - policy_names { ( - name = policy.crate_name, + match_arms_stream_display { ( + crate_name = policy.crate_name, + stream_struct_id = stream_struct_id + ) }, + stream_policy_names { ( + name = policy.crate_name ) } }); } else { @@ -120,8 +127,15 @@ async fn main() { crate_name = policy.crate_name, stream_struct_id = stream_struct_id ) }, + match_arms_stream_display { ( + crate_name = policy.crate_name, + stream_struct_id = stream_struct_id + ) }, policy_names { ( name = policy.crate_name, + ) }, + stream_policy_names { ( + name = policy.crate_name ) } }); } @@ -162,7 +176,9 @@ struct CollectedPolicy { stream_struct_id: Option<String>, } -async fn collect(policy_crate_path: &PathBuf) -> Option<CollectedPolicy> { +type MatchedFuncInfo = (String, bool, Option<String>, bool, Option<String>); + +async fn collect(policy_crate_path: &Path) -> Option<CollectedPolicy> { let lib_rs_path = policy_crate_path.join("src").join("lib.rs"); let lib_rs_content = fs::read_to_string(&lib_rs_path).await.ok()?; @@ -227,9 +243,7 @@ async fn collect(policy_crate_path: &PathBuf) -> Option<CollectedPolicy> { }) } -fn collect_matched_func( - lib_rs_content: &str, -) -> Option<(String, bool, Option<String>, bool, Option<String>)> { +fn collect_matched_func(lib_rs_content: &str) -> Option<MatchedFuncInfo> { let syntax_tree = syn::parse_file(lib_rs_content).ok()?; let mut matched_func = None; |
