@@ -8,7 +8,6 @@ use crate::html::format::Buffer;
88use std:: ffi:: OsStr ;
99use std:: fs;
1010use std:: path:: { Component , Path , PathBuf } ;
11- use std:: fmt;
1211use syntax:: source_map:: FileName ;
1312
1413crate fn render ( dst : & Path , scx : & mut SharedContext ,
@@ -121,7 +120,7 @@ impl<'a> SourceCollector<'a> {
121120 static_extra_scripts : & [ & format ! ( "source-script{}" , self . scx. resource_suffix) ] ,
122121 } ;
123122 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) ,
125124 & self . scx . themes ) ;
126125 self . scx . fs . write ( & cur, v. as_bytes ( ) ) ?;
127126 self . scx . local_sources . insert ( p. clone ( ) , href) ;
@@ -158,25 +157,19 @@ where
158157
159158/// Wrapper struct to render the source code of a file. This will do things like
160159/// 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 ) {
166161 let lines = s. lines ( ) . count ( ) ;
167162 let mut cols = 0 ;
168163 let mut tmp = lines;
169164 while tmp > 0 {
170165 cols += 1 ;
171166 tmp /= 10 ;
172167 }
173- write ! ( fmt , "<pre class=\" line-numbers\" >" ) ? ;
168+ write ! ( buf , "<pre class=\" line-numbers\" >" ) ;
174169 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) ;
176171 }
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 ) ) ;
182175}
0 commit comments