From f110630bf23d7c3db6d1fd17daa803165b978050 Mon Sep 17 00:00:00 2001 From: jokemanfire Date: Wed, 17 Jul 2024 10:48:59 +0800 Subject: [PATCH] Same mode name may import twice Change Vec to HashSet Signed-off-by: jokemanfire --- protobuf-codegen/src/gen/all.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/protobuf-codegen/src/gen/all.rs b/protobuf-codegen/src/gen/all.rs index 312b8dbe6..888d7f3f2 100644 --- a/protobuf-codegen/src/gen/all.rs +++ b/protobuf-codegen/src/gen/all.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; use protobuf::descriptor::FileDescriptorProto; use protobuf::reflect::FileDescriptor; @@ -33,7 +33,7 @@ pub(crate) fn gen_all( .map(|f| Ok((ProtoPath::new(f.proto().name())?, f))) .collect::>()?; - let mut mods = Vec::new(); + let mut mods = HashSet::new(); let customize = CustomizeElemCtx { for_elem: customize.clone(), @@ -49,7 +49,7 @@ pub(crate) fn gen_all( )); let gen_file_result = gen_file(file, &files_map, &root_scope, &customize, parser)?; results.push(gen_file_result.compiler_plugin_result); - mods.push(gen_file_result.mod_name); + mods.insert(gen_file_result.mod_name); } if customize.for_elem.inside_protobuf.unwrap_or(false) { @@ -57,7 +57,8 @@ pub(crate) fn gen_all( } if customize.for_elem.gen_mod_rs.unwrap_or(true) { - results.push(gen_mod_rs(&mods)); + let r_vec: Vec = mods.into_iter().collect(); + results.push(gen_mod_rs(&r_vec)); } Ok(results)