Skip to main content

Table

Struct Table 

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

A decorated table with borders, headers, and separators.

Implementations§

Source§

impl Table

Source

pub fn new(spec: TabularSpec, total_width: usize) -> Self

Create a new table with the given spec and total width.

Source

pub fn from_spec(spec: &FlatDataSpec, total_width: usize) -> Self

Create a table from a raw FlatDataSpec.

Source

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);
Source

pub fn border(self, border: BorderStyle) -> Self

Set the border style.

Source

pub fn header<S: Into<String>, I: IntoIterator<Item = S>>( self, headers: I, ) -> Self

Set the column headers.

Source

pub fn header_from_columns(self) -> Self

Set headers automatically from column specifications.

For each column, uses (in order of preference):

  1. The header field if set
  2. The key field if set
  3. The name field if set
  4. 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);
Source

pub fn header_style(self, style: impl Into<String>) -> Self

Set the header style name.

Source

pub fn row_separator(self, enable: bool) -> Self

Enable row separators between data rows.

Source

pub fn get_border(&self) -> BorderStyle

Get the border style.

Source

pub fn num_columns(&self) -> usize

Get the number of columns.

Source

pub fn row<S: AsRef<str>>(&self, values: &[S]) -> String

Format a data row.

Source

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));
Source

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));
Source

pub fn header_row(&self) -> String

Format the header row.

Source

pub fn separator_row(&self) -> String

Generate a horizontal separator row.

Source

pub fn top_border(&self) -> String

Generate the top border row.

Source

pub fn bottom_border(&self) -> String

Generate the bottom border row.

Source

pub fn render<S: AsRef<str>>(&self, rows: &[Vec<S>]) -> String

Render the complete table with all rows.

Includes top border, header (if set), separator, data rows, and bottom border.

Trait Implementations§

Source§

impl Clone for Table

Source§

fn clone(&self) -> Table

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Table

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Object for Table

Source§

fn get_value(self: &Arc<Self>, key: &Value) -> Option<Value>

Given a key, looks up the associated value.
Source§

fn enumerate(self: &Arc<Self>) -> Enumerator

Enumerates the object. Read more
Source§

fn call_method( self: &Arc<Self>, _state: &State<'_, '_>, name: &str, args: &[Value], ) -> Result<Value, Error>

The engine calls this to invoke a method on the object. Read more
Source§

fn repr(self: &Arc<Self>) -> ObjectRepr

Indicates the natural representation of an object. Read more
Source§

fn enumerator_len(self: &Arc<Self>) -> Option<usize>

Returns the length of the enumerator. Read more
Source§

fn is_true(self: &Arc<Self>) -> bool

Returns true if this object is considered true for if conditions. Read more
Source§

fn call( self: &Arc<Self>, state: &State<'_, '_>, args: &[Value], ) -> Result<Value, Error>

The engine calls this to invoke the object itself. Read more
Source§

fn custom_cmp(self: &Arc<Self>, other: &DynObject) -> Option<Ordering>

Custom comparison of this object against another object of the same type. Read more
Source§

fn render(self: &Arc<Self>, f: &mut Formatter<'_>) -> Result<(), Error>
where Self: Sized + 'static,

Formats the object for stringification. Read more

Auto Trait Implementations§

§

impl Freeze for Table

§

impl RefUnwindSafe for Table

§

impl Send for Table

§

impl Sync for Table

§

impl Unpin for Table

§

impl UnwindSafe for Table

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ObjectExt for T
where T: Object + Send + Sync + 'static,

Source§

fn mapped_enumerator<F>(self: &Arc<Self>, maker: F) -> Enumerator
where F: for<'a> FnOnce(&'a Self) -> Box<dyn Iterator<Item = Value> + Send + Sync + 'a> + Send + Sync + 'static, Self: Sized,

Creates a new iterator enumeration that projects into the given object. Read more
Source§

fn mapped_rev_enumerator<F>(self: &Arc<Self>, maker: F) -> Enumerator
where F: for<'a> FnOnce(&'a Self) -> Box<dyn DoubleEndedIterator<Item = Value> + Send + Sync + 'a> + Send + Sync + 'static, Self: Sized,

Creates a new reversible iterator enumeration that projects into the given object. Read more
Source§

fn try_iter( self: &Arc<Self>, ) -> Option<Box<dyn Iterator<Item = Value> + Send + Sync>>
where Self: 'static,

Iterates over this object. Read more
Source§

fn try_iter_pairs( self: &Arc<Self>, ) -> Option<Box<dyn Iterator<Item = (Value, Value)> + Send + Sync>>

Iterate over key and value at once.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more