@@ -33,7 +33,7 @@ use std::cmp::Ordering;
33
33
use std:: collections:: { BTreeMap , VecDeque } ;
34
34
use std:: default:: Default ;
35
35
use std:: error;
36
- use std:: fmt:: { self , Display , Formatter , Write as FmtWrite } ;
36
+ use std:: fmt:: { self , Formatter , Write as FmtWrite } ;
37
37
use std:: ffi:: OsStr ;
38
38
use std:: fs:: { self , File } ;
39
39
use std:: io:: prelude:: * ;
@@ -82,16 +82,14 @@ mod tests;
82
82
/// A pair of name and its optional document.
83
83
pub type NameDoc = ( String , Option < String > ) ;
84
84
85
- pub struct SlashChecker < ' a > ( pub & ' a str ) ;
86
-
87
- impl < ' a > Display for SlashChecker < ' a > {
88
- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
89
- if !self . 0 . ends_with ( "/" ) && !self . 0 . is_empty ( ) {
90
- write ! ( f, "{}/" , self . 0 )
85
+ crate fn ensure_trailing_slash ( v : & str ) -> impl fmt:: Display + ' _ {
86
+ crate :: html:: format:: display_fn ( move |f| {
87
+ if !v. ends_with ( "/" ) && !v. is_empty ( ) {
88
+ write ! ( f, "{}/" , v)
91
89
} else {
92
- write ! ( f, "{}" , self . 0 )
90
+ write ! ( f, "{}" , v )
93
91
}
94
- }
92
+ } )
95
93
}
96
94
97
95
#[ derive( Debug ) ]
@@ -106,7 +104,7 @@ impl error::Error for Error {
106
104
}
107
105
}
108
106
109
- impl Display for Error {
107
+ impl std :: fmt :: Display for Error {
110
108
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
111
109
let file = self . file . display ( ) . to_string ( ) ;
112
110
if file. is_empty ( ) {
@@ -1162,7 +1160,7 @@ themePicker.onblur = handleThemeButtonsBlur;
1162
1160
. iter( )
1163
1161
. map( |s| {
1164
1162
format!( "<li><a href=\" {}index.html\" >{}</li>" ,
1165
- SlashChecker ( s) , s)
1163
+ ensure_trailing_slash ( s) , s)
1166
1164
} )
1167
1165
. collect:: <String >( ) ) ;
1168
1166
let v = layout:: render ( & cx. shared . layout ,
@@ -2286,7 +2284,7 @@ fn print_item(cx: &Context, item: &clean::Item, buf: &mut Buffer) {
2286
2284
2287
2285
fn item_path ( ty : ItemType , name : & str ) -> String {
2288
2286
match ty {
2289
- ItemType :: Module => format ! ( "{}index.html" , SlashChecker ( name) ) ,
2287
+ ItemType :: Module => format ! ( "{}index.html" , ensure_trailing_slash ( name) ) ,
2290
2288
_ => format ! ( "{}.{}.html" , ty, name) ,
2291
2289
}
2292
2290
}
0 commit comments