Function to_grid

Source
pub fn to_grid(rows: impl IntoIterator<Item = impl Cells>) -> String
Expand description

Generate a table using the columns defined by Cells.

ยงExamples

use text_grid::*;
struct RowData {
    a: u32,
    b: u32,
}
impl Cells for RowData {
    fn fmt(f: &mut CellsFormatter<Self>) {
        f.column("a", |s| s.a);
        f.column("b", |s| s.b);
    }
}

let rows = [
    RowData { a: 300, b: 1 },
    RowData { a: 2, b: 200 },
];
let g = to_grid(rows);
assert_eq!(format!("\n{g}"), r#"
  a  |  b  |
-----|-----|
 300 |   1 |
   2 | 200 |
"#);