Struct codize::Codize

source ·
pub struct Codize {
    pub indent: usize,
    pub inline_condition: Box<dyn Fn(&Block) -> bool>,
    pub trailing_newline: bool,
}
Expand description

Codize formatter

This turns a Code into a string, joined with newlines.

There are formatting options you can set through its methods or by directly constructing it.

Fields§

§indent: usize

The number of spaces to indent per level.

§inline_condition: Box<dyn Fn(&Block) -> bool>

A function that determines whether a block should be inlined.

When the block is inlined, the body is put on the same line as the start and the end, and the body will be separated by a space instead of a newline. For example, you can set the block to inline if it only contains one line of code.

Note that this function is called on blocks of all levels. You can use the block starting and ending strings to do basic filtering

§trailing_newline: bool

If a trailing newline should be added when there is none

Implementations§

source§

impl Codize

source

pub fn indent(indent: usize) -> Self

Set indent

source

pub fn set_indent(self, indent: usize) -> Self

Set indent

source

pub fn always_inline() -> Self

Set the blocks to always inline

source

pub fn set_always_inline(self) -> Self

Set the blocks to always inline

source

pub fn inline_when<F>(condition: F) -> Self
where F: Fn(&Block) -> bool + 'static,

Set the inline condition

source

pub fn set_inline_when<F>(self, condition: F) -> Self
where F: Fn(&Block) -> bool + 'static,

Set the inline condition

source

pub fn trailing_newline(trailing_newline: bool) -> Self

Set if there should be trailing newline

source

pub fn set_trailing_newline(self, trailing_newline: bool) -> Self

Set if there should be trailing newline

Trait Implementations§

source§

impl Default for Codize

source§

fn default() -> Self

Create the default formatting

The default formatting is:

  • Indentation of 4 spaces
  • Blocks are never inlined
  • No trailing newline

Auto Trait Implementations§

§

impl Freeze for Codize

§

impl !RefUnwindSafe for Codize

§

impl !Send for Codize

§

impl !Sync for Codize

§

impl Unpin for Codize

§

impl !UnwindSafe for Codize

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.