IndentWriter

Struct IndentWriter 

Source
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>

Source

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.

Source

pub fn indent_str(&self) -> &str

Get the string used to indent each level.

Source§

impl<'i, W: Write> IndentWriter<'i, W>

Source

pub fn indent(&mut self) -> IndentWriter<'i, &mut IndentWriter<'i, W>>

Produce a new IndentWriter at one deeper indent level.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<'i, W> Debug for IndentWriter<'i, W>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'i, W> Write for IndentWriter<'i, W>
where W: Write,

Source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
Source§

fn write_char(&mut self, c: char) -> Result

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the write! macro with implementors of this trait. Read more

Auto Trait Implementations§

§

impl<'i, W> Freeze for IndentWriter<'i, W>
where W: Freeze,

§

impl<'i, W> RefUnwindSafe for IndentWriter<'i, W>
where W: RefUnwindSafe,

§

impl<'i, W> Send for IndentWriter<'i, W>
where W: Send,

§

impl<'i, W> Sync for IndentWriter<'i, W>
where W: Sync,

§

impl<'i, W> Unpin for IndentWriter<'i, W>
where W: Unpin,

§

impl<'i, W> UnwindSafe for IndentWriter<'i, W>
where W: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,