2121//!     playground: &None, 
2222//!     heading_offset: HeadingOffset::H2, 
2323//! }; 
24- //! let html = md.into_string(); 
24+ //! let mut html = String::new(); 
25+ //! md.write_into(&mut html).unwrap(); 
2526//! // ... something using html 
2627//! ``` 
2728
2829use  std:: borrow:: Cow ; 
2930use  std:: collections:: VecDeque ; 
30- use  std:: fmt:: Write ; 
31+ use  std:: fmt:: { self ,   Write } ; 
3132use  std:: iter:: Peekable ; 
3233use  std:: ops:: { ControlFlow ,  Range } ; 
3334use  std:: path:: PathBuf ; 
@@ -1328,16 +1329,13 @@ impl LangString {
13281329} 
13291330
13301331impl < ' a >  Markdown < ' a >  { 
1331-     pub  fn  into_string ( self )  -> String  { 
1332+     pub  fn  write_into ( self ,   f :   impl  fmt :: Write )  -> fmt :: Result  { 
13321333        // This is actually common enough to special-case 
13331334        if  self . content . is_empty ( )  { 
1334-             return  String :: new ( ) ; 
1335+             return  Ok ( ( ) ) ; 
13351336        } 
13361337
1337-         let  mut  s = String :: with_capacity ( self . content . len ( )  *  3  / 2 ) ; 
1338-         html:: push_html ( & mut  s,  self . into_iter ( ) ) ; 
1339- 
1340-         s
1338+         html:: write_html_fmt ( f,  self . into_iter ( ) ) 
13411339    } 
13421340
13431341    fn  into_iter ( self )  -> CodeBlocks < ' a ,  ' a ,  impl  Iterator < Item  = Event < ' a > > >  { 
@@ -1453,19 +1451,20 @@ impl MarkdownWithToc<'_> {
14531451
14541452        ( toc. into_toc ( ) ,  s) 
14551453    } 
1456-     pub ( crate )  fn  into_string ( self )  -> String  { 
1454+ 
1455+     pub ( crate )  fn  write_into ( self ,  mut  f :  impl  fmt:: Write )  -> fmt:: Result  { 
14571456        let  ( toc,  s)  = self . into_parts ( ) ; 
1458-         format ! ( "<nav id=\" rustdoc\" >{toc}</nav>{s}" ,  toc = toc. print( ) ) 
1457+         write ! ( f ,   "<nav id=\" rustdoc\" >{toc}</nav>{s}" ,  toc = toc. print( ) ) 
14591458    } 
14601459} 
14611460
14621461impl  MarkdownItemInfo < ' _ >  { 
1463-     pub ( crate )  fn  into_string ( self )  -> String  { 
1462+     pub ( crate )  fn  write_into ( self ,   mut   f :   impl  fmt :: Write )  -> fmt :: Result  { 
14641463        let  MarkdownItemInfo ( md,  ids)  = self ; 
14651464
14661465        // This is actually common enough to special-case 
14671466        if  md. is_empty ( )  { 
1468-             return  String :: new ( ) ; 
1467+             return  Ok ( ( ) ) ; 
14691468        } 
14701469        let  p = Parser :: new_ext ( md,  main_body_opts ( ) ) . into_offset_iter ( ) ; 
14711470
@@ -1475,19 +1474,15 @@ impl MarkdownItemInfo<'_> {
14751474            _ => event, 
14761475        } ) ; 
14771476
1478-         let  mut  s = String :: with_capacity ( md. len ( )  *  3  / 2 ) ; 
1479- 
14801477        ids. handle_footnotes ( |ids,  existing_footnotes| { 
14811478            let  p = HeadingLinks :: new ( p,  None ,  ids,  HeadingOffset :: H1 ) ; 
14821479            let  p = footnotes:: Footnotes :: new ( p,  existing_footnotes) ; 
14831480            let  p = TableWrapper :: new ( p. map ( |( ev,  _) | ev) ) ; 
14841481            let  p = p. filter ( |event| { 
14851482                !matches ! ( event,  Event :: Start ( Tag :: Paragraph )  | Event :: End ( TagEnd :: Paragraph ) ) 
14861483            } ) ; 
1487-             html:: push_html ( & mut  s,  p) ; 
1488-         } ) ; 
1489- 
1490-         s
1484+             html:: write_html_fmt ( & mut  f,  p) 
1485+         } ) 
14911486    } 
14921487} 
14931488
0 commit comments