@@ -267,22 +267,21 @@ pub(crate) fn extract(
267
267
Markdown ( PathBuf ) ,
268
268
}
269
269
270
- // convert all `Cargo.toml` manifest files to their respective product files
271
- // so after this conversion all of them are considered
270
+ // stage 1 - obtain canonical paths
272
271
let mut flow = VecDeque :: < PathBuf > :: with_capacity ( 32 ) ;
273
272
flow. extend ( paths. into_iter ( ) . filter_map ( |path_in| {
274
- if path_in. is_absolute ( ) {
273
+ let path = if path_in. is_absolute ( ) {
275
274
path_in. to_owned ( )
276
275
} else {
277
276
cwd. join ( & path_in)
278
- }
279
- . canonicalize ( )
280
- . ok ( )
277
+ } ;
278
+ info ! ( "Processing {} -> {}" , path_in . display ( ) , path . display ( ) ) ;
279
+ path . canonicalize ( ) . ok ( )
281
280
} ) ) ;
282
281
282
+ // stage 2 - check for manifest, .rs , .md files and directories
283
283
let mut files_to_check = Vec :: with_capacity ( 64 ) ;
284
- for path in flow {
285
- info ! ( "Processing {} -> {}" , path_in. display( ) , path. display( ) ) ;
284
+ while let Some ( path) = flow. pop_front ( ) {
286
285
files_to_check. push ( if let Ok ( meta) = path. metadata ( ) {
287
286
if meta. is_file ( ) {
288
287
match path. file_name ( ) . map ( |x| x. to_str ( ) ) . flatten ( ) {
@@ -295,16 +294,16 @@ pub(crate) fn extract(
295
294
}
296
295
}
297
296
} else if meta. is_dir ( ) {
298
- let cargo_toml = to_manifest_dir ( path) . unwrap ( ) . join ( "Cargo.toml" ) ;
297
+ let cargo_toml = to_manifest_dir ( & path) . unwrap ( ) . join ( "Cargo.toml" ) ;
299
298
if cargo_toml. is_file ( ) {
300
-
301
299
Extraction :: Manifest ( cargo_toml)
302
300
} else {
303
301
// @todo should we just collect all .rs files here instead?
304
302
305
303
// we know it's a directory, and we limit the entries to 0 levels,
306
- // will cause to yield all .rs files in that dir
307
- flow. extend ( traverse_with_depth_limit ( path, 0 ) ?. into_iter ( ) ) ;
304
+ // will cause to yield all "^.*\.rs$" files in that dir
305
+ // which is what we want in this case
306
+ flow. extend ( TraverseModulesIter :: with_depth_limit ( & path, 0 ) ?) ;
308
307
continue ;
309
308
}
310
309
} else {
@@ -315,26 +314,30 @@ pub(crate) fn extract(
315
314
} )
316
315
}
317
316
318
- let files_to_check = files_to_check. into_iter ( ) . try_fold :: < Vec < _ > , _ , Result < _ > > ( Vec :: with_capacity ( 64 ) , |mut acc, tagged_path| {
319
- match tagged_path {
320
- Extraction :: Manifest ( ref cargo_toml_path) => {
321
- let manifest_list = handle_manifest ( cargo_toml_path) ?;
322
- acc. extend ( manifest_list) ;
317
+ // stage 3 - resolve the manifest products and workspaces, warn about missing
318
+ let files_to_check = files_to_check
319
+ . into_iter ( )
320
+ . try_fold :: < Vec < _ > , _ , Result < _ > > ( Vec :: with_capacity ( 64 ) , |mut acc, tagged_path| {
321
+ match tagged_path {
322
+ Extraction :: Manifest ( ref cargo_toml_path) => {
323
+ let manifest_list = handle_manifest ( cargo_toml_path) ?;
324
+ acc. extend ( manifest_list) ;
325
+ }
326
+ Extraction :: Missing ( ref missing_path) => warn ! (
327
+ "File passed as argument or listed in Cargo.toml manifest does not exist: {}" ,
328
+ missing_path. display( )
329
+ ) ,
330
+ Extraction :: Source ( path) => acc. push ( CheckEntity :: Source ( path) ) ,
331
+ Extraction :: Markdown ( path) => acc. push ( CheckEntity :: Markdown ( path) ) ,
323
332
}
324
- Extraction :: Missing ( ref missing_path) => warn ! (
325
- "File passed as argument or listed in Cargo.toml manifest does not exist: {}" ,
326
- missing_path. display( )
327
- ) ,
328
- Extraction :: Source ( path) => acc. push ( CheckEntity :: Source ( path) ) ,
329
- Extraction :: Markdown ( path) => acc. push ( CheckEntity :: Markdown ( path) ) ,
330
- }
331
- Ok ( acc)
332
- } ) ?;
333
+ Ok ( acc)
334
+ } ) ?;
333
335
336
+ // stage 4 - expand from the passed source files, if recursive, recurse down the module train
334
337
let docs: Vec < Documentation > = files_to_check
335
338
. iter ( )
336
339
. try_fold :: < Vec < Documentation > , _ , Result < Vec < Documentation > > > (
337
- Vec :: with_capacity ( items . len ( ) ) ,
340
+ Vec :: with_capacity ( files_to_check . len ( ) ) ,
338
341
|mut acc, item| {
339
342
match item {
340
343
CheckEntity :: Source ( path) => {
0 commit comments