Trait text_grid::GridSchema
source · pub trait GridSchema {
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 GridSchema, use grid_schema.
Examples
use text_grid::*;
struct MyGridSchema {
len: usize,
}
impl GridSchema for MyGridSchema {
type Source = [u32];
fn fmt(&self, f: &mut CellsFormatter<&[u32]>) {
for i in 0..self.len {
f.column(i, |s| s[i]);
}
}
}
let mut g = Grid::new_with_schema(MyGridSchema { len: 3 });
g.push(&[1, 2, 3]);
g.push(&[4, 5, 6]);
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.