Struct text_grid::Grid

source ·
pub struct Grid<S> { /* private fields */ }
Expand description

A builder used to create plain-text table from struct that implement RowSource.

Examples

use text_grid::*;
struct RowData {
    a: u32,
    b: u32,
}
impl RowSource for RowData {
    fn fmt_row<'a>(w: &mut impl RowWrite<'a, Self>) {
        w.column("a", |s| s.a);
        w.column("b", |s| s.b);
    }
}

let mut g = Grid::new();
g.push_row(&RowData { a: 300, b: 1 });
g.push_row(&RowData { a: 2, b: 200 });

print!("{}", g);
  a  |  b  |
-----|-----|
 300 |   1 |
   2 | 200 |

Implementations§

Create a new Grid and prepare header rows.

Append a row to the bottom of grid.

Append a row separator to the bottom of grid.

Trait Implementations§

Formats the value using the given formatter. 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.

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.