diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-08-31 12:20:56 -0400 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-09-07 19:31:58 -0400 |
| commit | bb40d5fa498603f041dcf1092099c0b93928e442 (patch) | |
| tree | 94170b6e03e45be2e16984a9c7c4d50b9f4f8209 | |
| parent | 3f0e77f19c16eb3cd46390ab0082ad749cb1c5b5 (diff) | |
| download | rust-bb40d5fa498603f041dcf1092099c0b93928e442.tar.gz rust-bb40d5fa498603f041dcf1092099c0b93928e442.zip | |
Move Source to Buffer
| -rw-r--r-- | src/librustdoc/html/sources.rs | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index e94ae1d968e..d840683a7af 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -8,7 +8,6 @@ use crate::html::format::Buffer; use std::ffi::OsStr; use std::fs; use std::path::{Component, Path, PathBuf}; -use std::fmt; use syntax::source_map::FileName; crate fn render(dst: &Path, scx: &mut SharedContext, @@ -121,7 +120,7 @@ impl<'a> SourceCollector<'a> { static_extra_scripts: &[&format!("source-script{}", self.scx.resource_suffix)], }; let v = layout::render(&self.scx.layout, - &page, "", |buf: &mut Buffer| buf.from_display(Source(&contents)), + &page, "", |buf: &mut _| print_src(buf, &contents), &self.scx.themes); self.scx.fs.write(&cur, v.as_bytes())?; self.scx.local_sources.insert(p.clone(), href); @@ -158,11 +157,7 @@ where /// Wrapper struct to render the source code of a file. This will do things like /// adding line numbers to the left-hand side. -struct Source<'a>(&'a str); - -impl<'a> fmt::Display for Source<'a> { -fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - let Source(s) = *self; +fn print_src(buf: &mut Buffer, s: &str) { let lines = s.lines().count(); let mut cols = 0; let mut tmp = lines; @@ -170,13 +165,11 @@ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { cols += 1; tmp /= 10; } - write!(fmt, "<pre class=\"line-numbers\">")?; + write!(buf, "<pre class=\"line-numbers\">"); for i in 1..=lines { - write!(fmt, "<span id=\"{0}\">{0:1$}</span>\n", i, cols)?; + write!(buf, "<span id=\"{0}\">{0:1$}</span>\n", i, cols); } - write!(fmt, "</pre>")?; - write!(fmt, "{}", - highlight::render_with_highlighting(s, None, None, None))?; - Ok(()) -} + write!(buf, "</pre>"); + write!(buf, "{}", + highlight::render_with_highlighting(s, None, None, None)); } |
