]> git.lizzy.rs Git - rust.git/blobdiff - src/librustdoc/html/toc.rs
Rollup merge of #105682 - thomcc:expose-ptr-fmt, r=RalfJung
[rust.git] / src / librustdoc / html / toc.rs
index c55f2459a9ce2b26a71dbecd4cc0e8adc7bc4081..a12c2a6a16c32f15ba951310a5af304f855bf3e0 100644 (file)
@@ -2,7 +2,7 @@
 
 /// A (recursive) table of contents
 #[derive(Debug, PartialEq)]
-crate struct Toc {
+pub(crate) struct Toc {
     /// The levels are strictly decreasing, i.e.
     ///
     /// `entries[0].level >= entries[1].level >= ...`
@@ -26,7 +26,7 @@ fn count_entries_with_level(&self, level: u32) -> usize {
 }
 
 #[derive(Debug, PartialEq)]
-crate struct TocEntry {
+pub(crate) struct TocEntry {
     level: u32,
     sec_number: String,
     name: String,
@@ -36,7 +36,7 @@ fn count_entries_with_level(&self, level: u32) -> usize {
 
 /// Progressive construction of a table of contents.
 #[derive(PartialEq)]
-crate struct TocBuilder {
+pub(crate) struct TocBuilder {
     top_level: Toc,
     /// The current hierarchy of parent headings, the levels are
     /// strictly increasing (i.e., `chain[0].level < chain[1].level <
@@ -50,12 +50,12 @@ fn count_entries_with_level(&self, level: u32) -> usize {
 }
 
 impl TocBuilder {
-    crate fn new() -> TocBuilder {
+    pub(crate) fn new() -> TocBuilder {
         TocBuilder { top_level: Toc { entries: Vec::new() }, chain: Vec::new() }
     }
 
     /// Converts into a true `Toc` struct.
-    crate fn into_toc(mut self) -> Toc {
+    pub(crate) fn into_toc(mut self) -> Toc {
         // we know all levels are >= 1.
         self.fold_until(0);
         self.top_level
@@ -115,7 +115,7 @@ fn fold_until(&mut self, level: u32) {
     /// Push a level `level` heading into the appropriate place in the
     /// hierarchy, returning a string containing the section number in
     /// `<num>.<num>.<num>` format.
-    crate fn push(&mut self, level: u32, name: String, id: String) -> &str {
+    pub(crate) fn push(&mut self, level: u32, name: String, id: String) -> &str {
         assert!(level >= 1);
 
         // collapse all previous sections into their parents until we
@@ -163,21 +163,24 @@ fn fold_until(&mut self, level: u32) {
 
 impl Toc {
     fn print_inner(&self, v: &mut String) {
+        use std::fmt::Write as _;
+
         v.push_str("<ul>");
         for entry in &self.entries {
             // recursively format this table of contents
-            v.push_str(&format!(
+            let _ = write!(
+                v,
                 "\n<li><a href=\"#{id}\">{num} {name}</a>",
                 id = entry.id,
                 num = entry.sec_number,
                 name = entry.name
-            ));
+            );
             entry.children.print_inner(&mut *v);
             v.push_str("</li>");
         }
         v.push_str("</ul>");
     }
-    crate fn print(&self) -> String {
+    pub(crate) fn print(&self) -> String {
         let mut v = String::new();
         self.print_inner(&mut v);
         v