pub trait TableShapedView {
// Required methods
fn extract_headers(&self) -> Option<Vec<String>>;
fn is_table_shaped(&self) -> bool;
fn to_rows(&self) -> Vec<Vec<String>>;
}Expand description
Trait for working with table-shaped trees
Table-shaped trees have structure:
root
├── row_1
│ ├── column_a: "value"
│ └── column_b: "value"
└── row_2
├── column_a: "value"
└── column_b: "value"Required Methods§
Sourcefn extract_headers(&self) -> Option<Vec<String>>
fn extract_headers(&self) -> Option<Vec<String>>
Extract column headers from the first row’s children
Returns None if tree is empty or not table-shaped.
§Examples
use tree_fmt::{ RowBuilder, TableShapedView };
let tree = RowBuilder::new( vec![ "Name".into(), "Age".into() ] )
.add_row( vec![ "Alice".into(), "30".into() ] )
.build();
let headers = tree.extract_headers().unwrap();
assert_eq!( headers, vec![ "Name", "Age" ] );Sourcefn is_table_shaped(&self) -> bool
fn is_table_shaped(&self) -> bool
Check if tree has table structure (all rows have same child names)
§Examples
use tree_fmt::{ RowBuilder, TableShapedView };
let tree = RowBuilder::new( vec![ "Name".into() ] )
.add_row( vec![ "Alice".into() ] )
.build();
assert!( tree.is_table_shaped() );Sourcefn to_rows(&self) -> Vec<Vec<String>>
fn to_rows(&self) -> Vec<Vec<String>>
Extract row data as Vec<Vec
Each row becomes a vector of cell values.
§Examples
use tree_fmt::{ RowBuilder, TableShapedView };
let tree = RowBuilder::new( vec![ "Name".into(), "Age".into() ] )
.add_row( vec![ "Alice".into(), "30".into() ] )
.build();
let rows = tree.to_rows();
assert_eq!( rows.len(), 1 );
assert_eq!( rows[ 0 ], vec![ "Alice", "30" ] );