@@ -12,12 +12,14 @@ use quote::ToTokens;
1212use regex:: Regex ;
1313use syn:: Ident ;
1414
15+ #[ derive( Debug ) ]
1516struct Rpc {
1617 pub name : String ,
1718 pub input : String ,
1819 pub output : String ,
1920}
2021
22+ #[ derive( Debug ) ]
2123struct Plugin {
2224 pub plugin_name : String ,
2325
@@ -87,7 +89,7 @@ fn get_protoc() -> PathBuf {
8789
8890fn generate_messages_rs (
8991 protoc : & PathBuf ,
90- protos : & Vec < PathBuf > ,
92+ protos : & [ PathBuf ] ,
9193 include_dir : & str ,
9294 out_path : & Path ,
9395) -> FileDescriptorSet {
@@ -101,7 +103,7 @@ fn generate_messages_rs(
101103// Call the protoc code generation
102104fn messages_protoc_codegen (
103105 protoc : & PathBuf ,
104- protos : & Vec < PathBuf > ,
106+ protos : & [ PathBuf ] ,
105107 include_dir : & str ,
106108 out_path : & Path ,
107109) -> FileDescriptorSet {
@@ -115,43 +117,6 @@ fn messages_protoc_codegen(
115117
116118 let fd = std:: fs:: read ( fd) . unwrap ( ) ;
117119 prost_types:: FileDescriptorSet :: decode ( fd. as_slice ( ) ) . unwrap ( )
118-
119- /*protobuf_codegen::Codegen::new()
120- .customize(Customize::default().lite_runtime(false))
121- .customize_callback(AddHash)
122- .pure()
123- .include(include_dir)
124- .inputs(protos)
125- .out_dir(out_path)
126- .run_from_script();*/
127- }
128-
129- fn messages_generate_mod_rs ( protos : & Vec < PathBuf > , out_path : & Path ) {
130- let mut file = quote ! ( ) ;
131-
132- for proto in protos {
133- let mod_name = proto
134- . with_extension ( "" )
135- . file_name ( )
136- . unwrap ( )
137- . to_str ( )
138- . unwrap ( )
139- . to_string ( ) ;
140-
141- let mod_name: Ident = format_ident ! ( "{}" , mod_name) ;
142-
143- file. extend ( quote ! {
144- mod #mod_name;
145- pub use self :: #mod_name:: * ;
146- } ) ;
147- }
148- // Write mod.rs
149- let mut mod_rs_path = out_path. to_path_buf ( ) ;
150- mod_rs_path. push ( "mod.rs" ) ;
151- let tree = syn:: parse2 ( file) . unwrap ( ) ;
152- let formatted = prettyplease:: unparse ( & tree) ;
153-
154- std:: fs:: write ( mod_rs_path, formatted) . unwrap ( ) ;
155120}
156121
157122fn generate_stubs_rs ( fd : & FileDescriptorSet , protos : & Vec < PathBuf > , out_path : & Path ) {
@@ -197,7 +162,7 @@ fn generate_stubs_mod_rs(plugins: &Vec<Plugin>, file: &mut TokenStream) {
197162 let member_ident = plugin. member_ident . clone ( ) ;
198163 plugins_impl. extend ( quote ! {
199164 #[ doc = #doc]
200- pub fn #member_ident( & mut self ) -> crate :: stubs:: #struct_ident<TChannel > {
165+ pub fn #member_ident( & ' a mut self ) -> crate :: stubs:: #struct_ident<' a , TChannel > {
201166 crate :: stubs:: #struct_ident:: new( & mut self . channel)
202167 }
203168 } ) ;
@@ -215,7 +180,7 @@ fn generate_stubs_mod_rs(plugins: &Vec<Plugin>, file: &mut TokenStream) {
215180 }
216181 }
217182
218- impl <TChannel : crate :: Channel > Stubs <TChannel > {
183+ impl <' a , TChannel : crate :: Channel > Stubs <TChannel > {
219184 #plugins_impl
220185 }
221186
@@ -311,8 +276,7 @@ fn generate_stub_rs(fd: &FileDescriptorSet, plugin: &Plugin, file: &mut TokenStr
311276 value: i32 ,
312277 } ;
313278 prep = quote ! {
314- let mut request = IntMessage :: default ( ) ;
315- request. value = value;
279+ let request = IntMessage { value } ;
316280 }
317281 }
318282
@@ -331,8 +295,7 @@ fn generate_stub_rs(fd: &FileDescriptorSet, plugin: &Plugin, file: &mut TokenStr
331295 value: bool ,
332296 } ;
333297 prep = quote ! {
334- let mut request = SingleBool :: default ( ) ;
335- request. value = Some ( value) ;
298+ let request = SingleBool { value: Some ( value) } ;
336299 }
337300 }
338301
@@ -416,6 +379,9 @@ fn read_protos_rpcs(protos: &Vec<PathBuf>) -> Vec<Plugin> {
416379
417380 plugins. sort_by ( |a, b| a. plugin_name . cmp ( & b. plugin_name ) ) ;
418381
382+ dbg ! ( plugins) ;
383+ panic ! ( ) ;
384+
419385 plugins
420386}
421387
0 commit comments