Struct preserves_schema::syntax::block::Formatter

source ·
pub struct Formatter {
    pub width: usize,
    pub buffer: String,
    /* private fields */
}
Expand description

State needed for pretty-formatting of Emittables.

Fields§

§width: usize

Number of available columns. Used to decide between horizontal and vertical layouts.

§buffer: String

Mutable output buffer. Accumulates emitted text during writing.

Implementations§

source§

impl Formatter

source

pub fn new() -> Self

Construct a Formatter using DEFAULT_WIDTH and a four-space indent.

source

pub fn copy_empty(&self) -> Formatter

Construct a Formatter just like self but with an empty buffer.

source

pub fn indent_size(self) -> usize

Yields the indent size.

source

pub fn set_indent_size(&mut self, n: usize)

Updates the indent size.

source

pub fn write<E: Emittable>(&mut self, e: E)

Accumulates a text serialization of e in buffer.

source

pub fn newline(&mut self)

Emits a newline followed by indentation into buffer.

source

pub fn to_string<E: Emittable>(e: E) -> String

Creates a default Formatter, uses it to write e, and yields the contents of its buffer.

source

pub fn with_indent<R, F: FnOnce(&mut Self) -> R>(&mut self, f: F) -> R

Calls f in a context where the indentation has been increased by Formatter::indent_size spaces. Restores the indentation level after f returns. Yields the result of the call to f.

Trait Implementations§

source§

impl Default for Formatter

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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<L, N> Codec<N> for L
where N: NestedValue,

source§

fn parse<'a, T>(&'a self, value: &N) -> Result<T, ParseError>
where T: Parse<&'a L, N>,

Delegates to T::parse, using self as language and the given value as input.
source§

fn unparse<'a, T>(&'a self, value: &T) -> N
where T: Unparse<&'a L, N>,

Delegates to value.unparse, using self as language.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.