pub struct Table<R = VecRecords<CellInfo<'static>>> { /* private fields */ }
Expand description

The structure provides an interface for building a table for types that implements Tabled.

To build a string representation of a table you must use a std::fmt::Display. Or simply call .to_string() method.

The default table Style is Style::ascii, with a 1 left and right Padding.

Example

Basic usage

use tabled::Table;

let table = Table::new(&["Year", "2021"]);

With settings

use tabled::{Table, Style, Alignment};

let data = vec!["Hello", "2021"];
let mut table = Table::new(&data);
table.with(Style::psql()).with(Alignment::left());

println!("{}", table);

Implementations

New creates a Table instance.

If you use a reference iterator you’d better use FromIterator instead. As it has a different lifetime constraints and make less copies therefore.

Creates a builder from a data set given.

Example
use tabled::{Table, Tabled, object::Segment, ModifyObject, Alignment};

#[derive(Tabled)]
struct User {
    name: &'static str,
    #[tabled(inline("device::"))]
    device: Device,
}

#[derive(Tabled)]
enum Device {
    PC,
    Mobile
}

let data = vec![
    User { name: "Vlad", device: Device::Mobile },
    User { name: "Dimitry", device: Device::PC },
    User { name: "John", device: Device::PC },
];

let mut builder = Table::builder(data).index();
builder.set_index(0);
builder.transpose();

let table = builder.build()
    .with(Segment::new(1.., 1..).modify().with(Alignment::center()))
    .to_string();

assert_eq!(
    table,
    "+----------------+------+---------+------+\n\
     | name           | Vlad | Dimitry | John |\n\
     +----------------+------+---------+------+\n\
     | device::PC     |      |    +    |  +   |\n\
     +----------------+------+---------+------+\n\
     | device::Mobile |  +   |         |      |\n\
     +----------------+------+---------+------+"
)

Get a reference to the table’s cfg.

Get a reference to the table’s cfg.

Get a reference to the table’s records.

Get a reference to the table’s records.

With is a generic function which applies options to the Table.

It applies settings immediately.

A verification that first row is actually a header.

It’s true when Table::new and Table::builder is used. In many other cases it’s false.

Returns a table shape (count rows, count columns).

Returns an amount of rows in the table.

Returns an amount of columns in the table.

Returns a table shape (count rows, count columns).

Returns total widths of a table, including margin and vertical lines.

Returns total widths of a table, including margin and horizontal lines.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Creates a value from an iterator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.