@@ -8,7 +8,6 @@ use crate::html::format::Buffer;
8
8
use std:: ffi:: OsStr ;
9
9
use std:: fs;
10
10
use std:: path:: { Component , Path , PathBuf } ;
11
- use std:: fmt;
12
11
use syntax:: source_map:: FileName ;
13
12
14
13
crate fn render ( dst : & Path , scx : & mut SharedContext ,
@@ -121,7 +120,7 @@ impl<'a> SourceCollector<'a> {
121
120
static_extra_scripts : & [ & format ! ( "source-script{}" , self . scx. resource_suffix) ] ,
122
121
} ;
123
122
let v = layout:: render ( & self . scx . layout ,
124
- & page, "" , |buf : & mut Buffer | buf . from_display ( Source ( & contents) ) ,
123
+ & page, "" , |buf : & mut _ | print_src ( buf , & contents) ,
125
124
& self . scx . themes ) ;
126
125
self . scx . fs . write ( & cur, v. as_bytes ( ) ) ?;
127
126
self . scx . local_sources . insert ( p. clone ( ) , href) ;
@@ -158,25 +157,19 @@ where
158
157
159
158
/// Wrapper struct to render the source code of a file. This will do things like
160
159
/// adding line numbers to the left-hand side.
161
- struct Source < ' a > ( & ' a str ) ;
162
-
163
- impl < ' a > fmt:: Display for Source < ' a > {
164
- fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
165
- let Source ( s) = * self ;
160
+ fn print_src ( buf : & mut Buffer , s : & str ) {
166
161
let lines = s. lines ( ) . count ( ) ;
167
162
let mut cols = 0 ;
168
163
let mut tmp = lines;
169
164
while tmp > 0 {
170
165
cols += 1 ;
171
166
tmp /= 10 ;
172
167
}
173
- write ! ( fmt , "<pre class=\" line-numbers\" >" ) ? ;
168
+ write ! ( buf , "<pre class=\" line-numbers\" >" ) ;
174
169
for i in 1 ..=lines {
175
- write ! ( fmt , "<span id=\" {0}\" >{0:1$}</span>\n " , i, cols) ? ;
170
+ write ! ( buf , "<span id=\" {0}\" >{0:1$}</span>\n " , i, cols) ;
176
171
}
177
- write ! ( fmt, "</pre>" ) ?;
178
- write ! ( fmt, "{}" ,
179
- highlight:: render_with_highlighting( s, None , None , None ) ) ?;
180
- Ok ( ( ) )
181
- }
172
+ write ! ( buf, "</pre>" ) ;
173
+ write ! ( buf, "{}" ,
174
+ highlight:: render_with_highlighting( s, None , None , None ) ) ;
182
175
}
0 commit comments