pub struct IndentWriter<'i, W> { /* private fields */ }Expand description
A fmt::Write writer with indentation memory useful for formatting
structured data.
Implementations§
Source§impl<'i, W> IndentWriter<'i, W>
impl<'i, W> IndentWriter<'i, W>
Sourcepub fn new(indent: &'i str, writer: W) -> Self
pub fn new(indent: &'i str, writer: W) -> Self
Create a new writer from an existing writer and a proposed indent string.
The writer will start with no indent. Use IndentWriter::indent
to create an indented writer at the next level. Drop the writer returned
from IndentWriter::indent to return the current level.
Sourcepub fn indent_str(&self) -> &str
pub fn indent_str(&self) -> &str
Get the string used to indent each level.
Source§impl<'i, W: Write> IndentWriter<'i, W>
impl<'i, W: Write> IndentWriter<'i, W>
Sourcepub fn indent(&mut self) -> IndentWriter<'i, &mut IndentWriter<'i, W>>
pub fn indent(&mut self) -> IndentWriter<'i, &mut IndentWriter<'i, W>>
Produce a new IndentWriter at one deeper indent level.
Sourcepub fn indent_skip_first(
&mut self,
) -> IndentWriter<'i, &mut IndentWriter<'i, W>>
pub fn indent_skip_first( &mut self, ) -> IndentWriter<'i, &mut IndentWriter<'i, W>>
Produce a new IndentWriter at one deeper indent level, but don’t indent
the current line.
This produces a “hanging indent” where only the second line starts at the new indentation.
Sourcepub fn write_json<T: Serialize>(&mut self, data: &T) -> Result
pub fn write_json<T: Serialize>(&mut self, data: &T) -> Result
Write an object as prettified JSON
This will use the specified indent string to pretty-format the JSON via
serde_json::to_string_pretty.