RowBuilder

Struct RowBuilder 

Source
pub struct RowBuilder { /* private fields */ }
Expand description

Builder for constructing table-shaped trees

Creates trees where root has row nodes, and each row node has column-named children containing cell data.

§Examples

use tree_fmt::RowBuilder;

let tree = RowBuilder::new( vec![ "Name".into(), "Age".into() ] )
  .add_row( vec![ "Alice".into(), "30".into() ] )
  .add_row( vec![ "Bob".into(), "25".into() ] )
  .build();

assert_eq!( tree.children.len(), 2 );
assert_eq!( tree.children[ 0 ].name, "1" );

Implementations§

Source§

impl RowBuilder

Source

pub fn new(headers: Vec<String>) -> Self

Create a new table tree builder with column headers

Source

pub fn add_row(self, row: Vec<String>) -> Self

Add a row with automatic numeric naming (1, 2, 3, …)

Consumes and returns self for method chaining.

§Panics

Panics if row length doesnt match headers length

§Examples
use tree_fmt::RowBuilder;

let tree = RowBuilder::new( vec![ "A".into(), "B".into() ] )
  .add_row( vec![ "1".into(), "2".into() ] )
  .add_row( vec![ "3".into(), "4".into() ] )
  .build();

assert_eq!( tree.children.len(), 2 );
Source

pub fn add_row_mut(&mut self, row: Vec<String>)

Add a row with automatic numeric naming (non-consuming, for programmatic use)

This method takes &mut self for use in loops or when you need to keep the builder mutable.

§Panics

Panics if row length doesnt match headers length

Source

pub fn add_row_with_name(self, row_name: String, row: Vec<String>) -> Self

Add a row with custom row name

Consumes and returns self for method chaining.

§Panics

Panics if row length doesnt match headers length

§Examples
use tree_fmt::RowBuilder;

let tree = RowBuilder::new( vec![ "Name".into() ] )
  .add_row_with_name( "Alice".into(), vec![ "30".into() ] )
  .add_row_with_name( "Bob".into(), vec![ "25".into() ] )
  .build();

assert_eq!( tree.children[ 0 ].name, "Alice" );
Source

pub fn add_row_with_name_mut(&mut self, row_name: String, row: Vec<String>)

Add a row with custom row name (non-consuming, for programmatic use)

This method takes &mut self for use in loops or when you need to keep the builder mutable.

§Panics

Panics if row length doesnt match headers length

Source

pub fn build_view(self) -> TableView

Build as canonical TableView for use with Format trait

Creates a TableView that can be formatted using any formatter implementing the Format trait (json, yaml, table, text, etc).

§Examples
use tree_fmt::{ RowBuilder, TableFormatter, Format, TableConfig };

let view = RowBuilder::new( vec![ "Name".into(), "Age".into() ] )
  .add_row( vec![ "Alice".into(), "30".into() ] )
  .build_view();

// Format as table using Format trait
let formatter = TableFormatter::with_config( TableConfig::plain() );
let output = Format::format( &formatter, &view ).unwrap();
assert!( output.contains( "Alice" ) );
Source

pub fn build(self) -> TreeNode<String>

Build the final tree (for backward compatibility)

Returns a TreeNode<String> structure for use with legacy formatters. For new code, prefer build_view() which returns the canonical TableView.

Trait Implementations§

Source§

impl Debug for RowBuilder

Source§

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

Formats the value using the given formatter. 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.