TreeFormatter

Struct TreeFormatter 

Source
pub struct TreeFormatter { /* private fields */ }

Implementations§

Source§

impl TreeFormatter

Source

pub fn new() -> Self

Create a new TreeFormatter.

Source

pub fn finish(self) -> String

Get the formatted output.

Source

pub fn root(&mut self, content: &str) -> Result

Display a root node (no indentation prefix). Only use this for the very top-level node.

Source

pub fn field(&mut self, is_last: bool, name: &str, value: &str) -> Result

Display a field with a name and value.

Source

pub fn field_with_child<T: TreeDisplay>( &mut self, is_last: bool, name: &str, value: &T, source: &str, ) -> Result

Display a field with a child node that implements TreeDisplay.

Source

pub fn field_option<T: TreeDisplay>( &mut self, is_last: bool, name: &str, value: &Option<T>, source: &str, ) -> Result

Display an optional field.

Source

pub fn field_vec<T: TreeDisplay>( &mut self, is_last: bool, name: &str, items: &[T], source: &str, ) -> Result

Display a vector of items.

Source

pub fn field_array<T: TreeDisplay, const N: usize>( &mut self, is_last: bool, name: &str, items: &[T; N], source: &str, ) -> Result

Display an array of items.

Source

pub fn field_tuple2<T1: TreeDisplay, T2: TreeDisplay>( &mut self, is_last: bool, name: &str, value: &(T1, T2), source: &str, ) -> Result

Display a tuple of 2 items.

Source

pub fn format_raw(&self, span: Span, source: &str) -> String

Extract and format raw source text from a span.

If the text is longer than 40 characters, it will be truncated to show the first 20 and last 20 characters with “…” in the middle. Newlines and other whitespace are normalized to single spaces.

Trait Implementations§

Source§

impl Default for TreeFormatter

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

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.