@@ -2,7 +2,7 @@ use std::ffi::OsString;
2
2
use std:: fs;
3
3
use std:: path:: { Path , PathBuf } ;
4
4
5
- use anyhow:: { anyhow, bail , Context , Result } ;
5
+ use anyhow:: { anyhow, Context , Result } ;
6
6
7
7
struct DocData < ' a > {
8
8
topic : & ' a str ,
@@ -19,13 +19,10 @@ fn index_html(doc: &DocData<'_>, wpath: &Path) -> Option<PathBuf> {
19
19
}
20
20
21
21
fn dir_into_vec ( dir : & Path ) -> Result < Vec < OsString > > {
22
- let entries = fs:: read_dir ( dir) . with_context ( || format ! ( "Failed to read_dir {dir:?}" ) ) ?;
23
- let mut v = Vec :: new ( ) ;
24
- for entry in entries {
25
- let entry = entry?;
26
- v. push ( entry. file_name ( ) ) ;
27
- }
28
- Ok ( v)
22
+ fs:: read_dir ( dir)
23
+ . with_context ( || format ! ( "Failed to read_dir {dir:?}" ) ) ?
24
+ . map ( |f| Ok ( f?. file_name ( ) ) )
25
+ . collect ( )
29
26
}
30
27
31
28
fn search_path ( doc : & DocData < ' _ > , wpath : & Path , keywords : & [ & str ] ) -> Result < PathBuf > {
@@ -118,18 +115,14 @@ pub(crate) fn local_path(root: &Path, topic: &str) -> Result<PathBuf> {
118
115
// topic.split.count cannot be 0
119
116
let subpath_os_path = match topic_vec. len ( ) {
120
117
1 => match topic {
121
- "std" | "core" | "alloc" => match index_html ( & doc, & work_path) {
122
- Some ( f) => f,
123
- None => bail ! ( format!( "No document for '{}'" , doc. topic) ) ,
124
- } ,
125
- _ => {
126
- let std = PathBuf :: from ( "std" ) ;
127
- let search_keywords = match forced_keyword {
128
- Some ( k) => k,
129
- None => keywords_top,
130
- } ;
131
- search_path ( & doc, & std, & search_keywords) ?
118
+ "std" | "core" | "alloc" => {
119
+ index_html ( & doc, & work_path) . context ( anyhow ! ( "No document for '{}'" , doc. topic) ) ?
132
120
}
121
+ _ => search_path (
122
+ & doc,
123
+ Path :: new ( "std" ) ,
124
+ & forced_keyword. unwrap_or ( keywords_top) ,
125
+ ) ?,
133
126
} ,
134
127
2 => match index_html ( & doc, & work_path) {
135
128
Some ( f) => f,
0 commit comments