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
impl RowBuilder
Sourcepub fn add_row(self, row: Vec<String>) -> Self
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 );Sourcepub fn add_row_mut(&mut self, row: Vec<String>)
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
Sourcepub fn add_row_with_name(self, row_name: String, row: Vec<String>) -> Self
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" );Sourcepub fn add_row_with_name_mut(&mut self, row_name: String, row: Vec<String>)
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
Sourcepub fn build_view(self) -> TableView
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" ) );