Skip to main content

Table

Struct Table 

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

A simple table builder for rendering tabular CLI output.

§Examples

use blazer::table::Table;

let mut table = Table::new(vec!["Name", "Age", "City"]);
table.add_row(vec!["Alice", "30", "NYC"]);
table.add_row(vec!["Bob", "25", "LA"]);
println!("{}", table.render());

Implementations§

Source§

impl Table

Source

pub fn new(headers: Vec<&str>) -> Self

Creates a new table with the given column headers.

Examples found in repository?
examples/table_demo.rs (line 4)
3fn main() {
4    let mut table = Table::new(vec!["Task", "Status", "Duration"])
5        .with_borders(Borders::EMPTY)
6        .with_alignment(Alignment::Center);
7    table.add_row(vec!["build", "ok", "4.2s"]);
8    table.add_row(vec!["test", "failed", "12.9s"]);
9    table.add_row(vec!["lint", "ok", "1.1s"]);
10
11
12    table.print();
13}
Source

pub fn with_alignment(self, alignment: Alignment) -> Self

Sets the alignment used for all cells.

Examples found in repository?
examples/table_demo.rs (line 6)
3fn main() {
4    let mut table = Table::new(vec!["Task", "Status", "Duration"])
5        .with_borders(Borders::EMPTY)
6        .with_alignment(Alignment::Center);
7    table.add_row(vec!["build", "ok", "4.2s"]);
8    table.add_row(vec!["test", "failed", "12.9s"]);
9    table.add_row(vec!["lint", "ok", "1.1s"]);
10
11
12    table.print();
13}
Source

pub fn with_borders(self, borders: Borders) -> Self

Sets the border characters used for the table.

Examples found in repository?
examples/table_demo.rs (line 5)
3fn main() {
4    let mut table = Table::new(vec!["Task", "Status", "Duration"])
5        .with_borders(Borders::EMPTY)
6        .with_alignment(Alignment::Center);
7    table.add_row(vec!["build", "ok", "4.2s"]);
8    table.add_row(vec!["test", "failed", "12.9s"]);
9    table.add_row(vec!["lint", "ok", "1.1s"]);
10
11
12    table.print();
13}
Source

pub fn borderless(self) -> Self

Disables all borders.

Source

pub fn with_padding(self, padding: Padding) -> Self

Sets the padding used for all cells.

Source

pub fn add_row(&mut self, row: Vec<&str>)

Adds a row of data to the table.

Rows with fewer cells than there are headers will have missing cells rendered as empty strings.

Examples found in repository?
examples/table_demo.rs (line 7)
3fn main() {
4    let mut table = Table::new(vec!["Task", "Status", "Duration"])
5        .with_borders(Borders::EMPTY)
6        .with_alignment(Alignment::Center);
7    table.add_row(vec!["build", "ok", "4.2s"]);
8    table.add_row(vec!["test", "failed", "12.9s"]);
9    table.add_row(vec!["lint", "ok", "1.1s"]);
10
11
12    table.print();
13}
Source

pub fn render(&self) -> String

Renders the table as a formatted, box-drawn string ready to print.

Source

pub fn print(&self)

Renders and prints the table directly to stdout.

Examples found in repository?
examples/table_demo.rs (line 12)
3fn main() {
4    let mut table = Table::new(vec!["Task", "Status", "Duration"])
5        .with_borders(Borders::EMPTY)
6        .with_alignment(Alignment::Center);
7    table.add_row(vec!["build", "ok", "4.2s"]);
8    table.add_row(vec!["test", "failed", "12.9s"]);
9    table.add_row(vec!["lint", "ok", "1.1s"]);
10
11
12    table.print();
13}

Trait Implementations§

Source§

impl Display for Table

Source§

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

Formats the value using the given formatter. 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 UnsafeUnpin 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.