pub struct Table { /* private fields */ }Expand description
A decorated table with borders, headers, and separators.
Implementations§
Source§impl Table
impl Table
Sourcepub fn new(spec: TabularSpec, total_width: usize) -> Self
pub fn new(spec: TabularSpec, total_width: usize) -> Self
Create a new table with the given spec and total width.
Sourcepub fn from_spec(spec: &FlatDataSpec, total_width: usize) -> Self
pub fn from_spec(spec: &FlatDataSpec, total_width: usize) -> Self
Create a table from a raw FlatDataSpec.
Sourcepub fn from_type<T: Tabular>(total_width: usize) -> Self
pub fn from_type<T: Tabular>(total_width: usize) -> Self
Create a table from a type that implements Tabular.
This constructor uses the TabularSpec generated by the #[derive(Tabular)]
macro to configure the table.
§Example
use standout::tabular::{Tabular, Table, BorderStyle};
use serde::Serialize;
#[derive(Serialize, Tabular)]
#[tabular(separator = " | ")]
struct Task {
#[col(width = 8, header = "ID")]
id: String,
#[col(width = "fill", header = "Title")]
title: String,
}
let table = Table::from_type::<Task>(80)
.header_from_columns()
.border(BorderStyle::Light);Sourcepub fn border(self, border: BorderStyle) -> Self
pub fn border(self, border: BorderStyle) -> Self
Set the border style.
Sourcepub fn header<S: Into<String>, I: IntoIterator<Item = S>>(
self,
headers: I,
) -> Self
pub fn header<S: Into<String>, I: IntoIterator<Item = S>>( self, headers: I, ) -> Self
Set the column headers.
Sourcepub fn header_from_columns(self) -> Self
pub fn header_from_columns(self) -> Self
Set headers automatically from column specifications.
For each column, uses (in order of preference):
- The
headerfield if set - The
keyfield if set - The
namefield if set - Empty string
§Example
let spec = TabularSpec::builder()
.column(Col::fixed(8).header("ID"))
.column(Col::min(10).key("author").header("Author"))
.column(Col::fill().named("message")) // Uses name as fallback
.build();
let table = Table::new(spec, 80)
.header_from_columns() // Headers: ["ID", "Author", "message"]
.border(BorderStyle::Light);Sourcepub fn header_style(self, style: impl Into<String>) -> Self
pub fn header_style(self, style: impl Into<String>) -> Self
Set the header style name.
Sourcepub fn row_separator(self, enable: bool) -> Self
pub fn row_separator(self, enable: bool) -> Self
Enable row separators between data rows.
Sourcepub fn get_border(&self) -> BorderStyle
pub fn get_border(&self) -> BorderStyle
Get the border style.
Sourcepub fn num_columns(&self) -> usize
pub fn num_columns(&self) -> usize
Get the number of columns.
Sourcepub fn row_from<T: Serialize>(&self, value: &T) -> String
pub fn row_from<T: Serialize>(&self, value: &T) -> String
Format a data row by extracting values from a serializable struct.
This method extracts field values based on each column’s key or name.
See TabularFormatter::row_from for details on field extraction.
§Example
use serde::Serialize;
#[derive(Serialize)]
struct Record { name: String, status: String }
let table = Table::new(spec, 80);
let record = Record { name: "Alice".into(), status: "active".into() };
println!("{}", table.row_from(&record));Sourcepub fn row_from_trait<T: TabularRow>(&self, value: &T) -> String
pub fn row_from_trait<T: TabularRow>(&self, value: &T) -> String
Format a data row using the TabularRow trait.
This method uses the optimized to_row() implementation generated by
#[derive(TabularRow)], avoiding JSON serialization overhead.
§Example
use standout::tabular::{TabularRow, Tabular, Table, BorderStyle};
#[derive(Tabular, TabularRow)]
#[tabular(separator = " | ")]
struct Task {
#[col(width = 8)]
id: String,
#[col(width = "fill")]
title: String,
}
let table = Table::from_type::<Task>(80).border(BorderStyle::Light);
let task = Task {
id: "TSK-001".to_string(),
title: "Implement feature".to_string(),
};
println!("{}", table.row_from_trait(&task));Sourcepub fn header_row(&self) -> String
pub fn header_row(&self) -> String
Format the header row.
Sourcepub fn separator_row(&self) -> String
pub fn separator_row(&self) -> String
Generate a horizontal separator row.
Sourcepub fn top_border(&self) -> String
pub fn top_border(&self) -> String
Generate the top border row.
Sourcepub fn bottom_border(&self) -> String
pub fn bottom_border(&self) -> String
Generate the bottom border row.
Trait Implementations§
Source§impl Object for Table
impl Object for Table
Source§fn get_value(self: &Arc<Self>, key: &Value) -> Option<Value>
fn get_value(self: &Arc<Self>, key: &Value) -> Option<Value>
Source§fn call_method(
self: &Arc<Self>,
_state: &State<'_, '_>,
name: &str,
args: &[Value],
) -> Result<Value, Error>
fn call_method( self: &Arc<Self>, _state: &State<'_, '_>, name: &str, args: &[Value], ) -> Result<Value, Error>
Source§fn repr(self: &Arc<Self>) -> ObjectRepr
fn repr(self: &Arc<Self>) -> ObjectRepr
Source§fn enumerator_len(self: &Arc<Self>) -> Option<usize>
fn enumerator_len(self: &Arc<Self>) -> Option<usize>
Source§fn is_true(self: &Arc<Self>) -> bool
fn is_true(self: &Arc<Self>) -> bool
true if this object is considered true for if conditions. Read more