pub struct PrettyWriter { /* private fields */ }
Expand description

Used to generate pretty indented code

Implementations§

source§

impl PrettyWriter

source

pub fn new() -> Self

source

pub fn extend(&mut self, other: PrettyWriter)

Combines this writer with another one.

open brackets are inherited, the current string is indented with additional indentation to match this writers indentation level. If the indentation level is non-zero, it’s added to this writer’s. Any prefixes are ignored.

source

pub fn newline(&mut self) -> &mut Self

Inserts a newline character inline

source

pub fn write_line(&mut self, line: &str) -> &mut Self

Writes a line at the current indentation level and append a newline at the end

source

pub fn write_no_newline(&mut self, line: &str) -> &mut Self

Writes without adding newline but keeps the indentation

source

pub fn write_postfixed_line(&mut self, line: &str, postfix: &str) -> &mut Self

Writes a postfixed (after main text, before newline) line at the current indentation level and append a newline at the end

source

pub fn write_inline(&mut self, line: &str) -> &mut Self

Writes a line without adding indentation or a newline

source

pub fn write_indentation(&mut self) -> &mut Self

Writes indentation only, useful if you need to follow this by write_inline

source

pub fn set_prefix(&mut self, prefix: Cow<'static, str>) -> &mut Self

Sets a prefix to be appended before every line written

source

pub fn clear_prefix(&mut self) -> &mut Self

Clears the set prefix

source

pub fn indent(&mut self) -> &mut Self

Increases intendation level permamently, does not write to the output yet

source

pub fn dedent(&mut self) -> &mut Self

Decrases intendation level permamently, does not write to the output yet

source

pub fn open_paren(&mut self) -> &mut Self

Opens parenthesised section

source

pub fn close_paren(&mut self) -> &mut Self

Closes parenthesised section

source

pub fn open_brace(&mut self) -> &mut Self

Opens braceed section

source

pub fn close_brace(&mut self) -> &mut Self

Closes braced section

source

pub fn open_bracket(&mut self) -> &mut Self

Opens bracketed section

source

pub fn close_bracket(&mut self) -> &mut Self

Closes bracketed section

source

pub fn finish(self) -> String

Consumes self and produces the output string, panics if there is unclosed parenthesis/brackets etc.

Trait Implementations§

source§

impl Default for PrettyWriter

source§

fn default() -> PrettyWriter

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