Trait text_grid::CellsSchema
source · pub trait CellsSchema {
type Source: ?Sized;
// Required method
fn fmt(&self, f: &mut CellsFormatter<'_, '_, Self::Source>);
}
Expand description
Column definitions.
Define columns using CellsFormatter
.
To dynamically create a CellsSchema
, use cells_schema
.
§Examples
use text_grid::*;
struct MyCellsSchema {
len: usize,
}
impl CellsSchema for MyCellsSchema {
type Source = [u32; 3];
fn fmt(&self, f: &mut CellsFormatter<[u32; 3]>) {
for i in 0..self.len {
f.column(i, |s| s[i]);
}
}
}
let rows = [
[1, 2, 3],
[4, 5, 6],
];
let schema = MyCellsSchema { len: 3 };
let g = to_grid_with_schema(rows, schema);
assert_eq!(format!("\n{g}"), r#"
0 | 1 | 2 |
---|---|---|
1 | 2 | 3 |
4 | 5 | 6 |
"#);
Required Associated Types§
Required Methods§
sourcefn fmt(&self, f: &mut CellsFormatter<'_, '_, Self::Source>)
fn fmt(&self, f: &mut CellsFormatter<'_, '_, Self::Source>)
Define column information. see CellsFormatter
for details.