pub struct Printer { /* private fields */ }
Expand description
Maintains an internal state describing how to display a byte array.
It can write to an arbitrary std::fmt::Write
implementation using the
method Printer::write_to
.
Implementations§
Source§impl Printer
impl Printer
Sourcepub fn new(quote_style: QuoteStyle) -> Self
pub fn new(quote_style: QuoteStyle) -> Self
Returns a new Printer with the chosen quoting style.
Sourcepub fn write_to<I, W>(&self, bytes: I, writer: &mut W) -> Result
pub fn write_to<I, W>(&self, bytes: I, writer: &mut W) -> Result
Writes the formatted bytes to an arbitrary std::fmt::Write
implementation.
This method iterates through the byte array and calls writer.write_char
or writer.write_str
as appropriate. The performance of this method thus
depends on the implementation of the underlying writer. If a writer doesn’t
implement good buffering, or if each call to write
makes a system call
to do IO, this can be inefficient.
The helper method Printer::into_string
is a thin wrapper around this
method, calling write_to
with a String
as its writer. String
implements
fmt::Write
with methods like String::push
and String::push_str
, which
should be adequately performant for most uses. If the use case calls for it,
the user can always implement their own writer with custom buffering.
Sourcepub fn into_string<I>(&self, bytes: I) -> String
pub fn into_string<I>(&self, bytes: I) -> String
Returns a string displaying the bytes.
Trait Implementations§
Source§impl Default for Printer
Returns a printer that doesn’t quote its output.
impl Default for Printer
Returns a printer that doesn’t quote its output.
This is equivalent to Printer::new(QuoteStyle::None)
.