@@ -25,17 +25,15 @@ fn find_generated_rust_files(out_dir: &Path) -> ProtocResult<BTreeSet<PathBuf>>
25
25
for f in find_generated_rust_files ( & path) ? {
26
26
all_rs_files. insert ( f) ;
27
27
}
28
- } else {
29
- if let Some ( ext) = path. extension ( ) {
30
- if ext == "rs" {
31
- all_rs_files. insert ( path) ;
32
- }
33
- } else if let Some ( name) = path. file_name ( ) {
34
- if name == "_" {
35
- let rs_name = path. parent ( ) . expect ( "Failed to get parent" ) . join ( "_.rs" ) ;
36
- fs:: rename ( & path, & rs_name) . map_err ( from_error) ?;
37
- all_rs_files. insert ( rs_name) ;
38
- }
28
+ } else if let Some ( ext) = path. extension ( ) {
29
+ if ext == "rs" {
30
+ all_rs_files. insert ( path) ;
31
+ }
32
+ } else if let Some ( name) = path. file_name ( ) {
33
+ if name == "_" {
34
+ let rs_name = path. parent ( ) . expect ( "Failed to get parent" ) . join ( "_.rs" ) ;
35
+ fs:: rename ( & path, & rs_name) . map_err ( from_error) ?;
36
+ all_rs_files. insert ( rs_name) ;
39
37
}
40
38
}
41
39
}
@@ -224,11 +222,11 @@ fn compute_proto_package_info(
224
222
crate_name : & str ,
225
223
protoc : & Path ,
226
224
includes : & BTreeSet < String > ,
227
- proto_paths : & Vec < String > ,
225
+ proto_paths : & [ String ] ,
228
226
) -> ProtocResult < BTreeSet < String > > {
229
227
let mut extern_paths = BTreeSet :: new ( ) ;
230
228
for proto_file in proto_files. iter ( ) {
231
- let output = process:: Command :: new ( & protoc)
229
+ let output = process:: Command :: new ( protoc)
232
230
. args ( includes. iter ( ) . map ( |include| format ! ( "-I{}" , include) ) )
233
231
. arg ( "--print_free_field_numbers" )
234
232
. args (
@@ -259,16 +257,16 @@ fn compute_proto_package_info(
259
257
}
260
258
261
259
let ( absolute, _) = text
262
- . split_once ( " " )
260
+ . split_once ( ' ' )
263
261
. ok_or_else ( || format ! ( "Failed to split line: {}" , text) ) ?;
264
262
265
263
let mut package = "" ;
266
264
let mut symbol_name = absolute;
267
- if let Some ( ( package_, symbol_name_) ) = absolute. rsplit_once ( "." ) {
265
+ if let Some ( ( package_, symbol_name_) ) = absolute. rsplit_once ( '.' ) {
268
266
package = package_;
269
267
symbol_name = symbol_name_;
270
268
}
271
- let symbol = format ! ( "{}::{}" , package. replace( "." , "::" ) , symbol_name) ;
269
+ let symbol = format ! ( "{}::{}" , package. replace( '.' , "::" ) , symbol_name) ;
272
270
let extern_path = format ! ( ".{}={}::{}" , absolute, crate_name, symbol. trim_matches( ':' ) ) ;
273
271
if !extern_paths. insert ( extern_path. clone ( ) ) {
274
272
panic ! ( "Duplicate extern: {}" , extern_path) ;
@@ -335,23 +333,27 @@ impl Args {
335
333
// for the process runner and arguments for protoc and potentially spawn
336
334
// additional arguments needed by prost.
337
335
for arg in env:: args ( ) . skip ( 1 ) {
338
- if !arg. starts_with ( "-" ) {
336
+ if !arg. starts_with ( '-' ) {
339
337
proto_files. insert ( PathBuf :: from ( arg) ) ;
340
338
continue ;
341
339
}
342
340
343
341
if arg. starts_with ( "-I" ) {
344
- includes. insert ( arg[ 2 ..] . to_string ( ) ) ;
342
+ includes. insert (
343
+ arg. strip_prefix ( "-I" )
344
+ . expect ( "Failed to strip -I" )
345
+ . to_string ( ) ,
346
+ ) ;
345
347
continue ;
346
348
}
347
349
348
- if !arg. contains ( "=" ) {
350
+ if !arg. contains ( '=' ) {
349
351
extra_args. push ( arg) ;
350
352
continue ;
351
353
}
352
354
353
355
let part = arg
354
- . split_once ( "=" )
356
+ . split_once ( '=' )
355
357
. ok_or_else ( || format ! ( "Failed to parse argument `{arg}`" , ) ) ?;
356
358
match part {
357
359
( "--protoc" , value) => {
@@ -369,7 +371,7 @@ impl Args {
369
371
}
370
372
( "--package_info_output" , value) => {
371
373
let ( key, value) = value
372
- . split_once ( "=" )
374
+ . split_once ( '=' )
373
375
. map ( |( a, b) | ( a. to_string ( ) , PathBuf :: from ( b) ) )
374
376
. expect ( "Failed to parse package info output" ) ;
375
377
crate_name = Some ( key) ;
@@ -539,7 +541,7 @@ fn main() -> ProtocResult<()> {
539
541
// Write outputs
540
542
fs:: write ( & out_librs, generate_lib_rs ( & rust_files, is_tonic) ?) . map_err ( from_error) ?;
541
543
fs:: write (
542
- & package_info_file,
544
+ package_info_file,
543
545
package_info. into_iter ( ) . collect :: < Vec < _ > > ( ) . join ( "\n " ) ,
544
546
)
545
547
. map_err ( from_error) ?;
0 commit comments