pub struct Grid<R: ?Sized, S = DefaultCellsSchema<R>> { /* private fields */ }Expand description
A builder used to create plain-text table from row values.
Generate a table using the columns defined by CellsFormatter.
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 mut g = Grid::new();
g.push(&RowData { a: 300, b: 1 });
g.push(&RowData { a: 2, b: 200 });
assert_eq!(format!("\n{g}"), r#"
a | b |
-----|-----|
300 | 1 |
2 | 200 |
"#);Implementations§
source§impl<R: Cells + ?Sized> Grid<R, DefaultCellsSchema<R>>
impl<R: Cells + ?Sized> Grid<R, DefaultCellsSchema<R>>
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new Grid with DefaultCellsSchema and prepare header rows.
source§impl<R: ?Sized, S: CellsSchema<Source = R>> Grid<S::Source, S>
impl<R: ?Sized, S: CellsSchema<Source = R>> Grid<S::Source, S>
sourcepub fn with_schema(schema: S) -> Self
pub fn with_schema(schema: S) -> Self
Create a new Grid with specified schema and prepare header rows.
source§impl<R: ?Sized, S: CellsSchema<Source = R>> Grid<R, S>
impl<R: ?Sized, S: CellsSchema<Source = R>> Grid<R, S>
sourcepub fn push_separator(&mut self)
pub fn push_separator(&mut self)
Append a row separator to the bottom of the grid.
Trait Implementations§
source§impl<'a, R, S: CellsSchema<Source = R>> Extend<&'a R> for Grid<R, S>
impl<'a, R, S: CellsSchema<Source = R>> Extend<&'a R> for Grid<R, S>
source§fn extend<T: IntoIterator<Item = &'a R>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = &'a R>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
source§impl<R, S: CellsSchema<Source = R>> Extend<R> for Grid<R, S>
impl<R, S: CellsSchema<Source = R>> Extend<R> for Grid<R, S>
source§fn extend<T: IntoIterator<Item = R>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = R>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
source§impl<R: Cells> FromIterator<R> for Grid<R>
impl<R: Cells> FromIterator<R> for Grid<R>
source§fn from_iter<T: IntoIterator<Item = R>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = R>>(iter: T) -> Self
Creates a value from an iterator. Read more
Auto Trait Implementations§
impl<R: ?Sized, S> RefUnwindSafe for Grid<R, S>where
S: RefUnwindSafe,
impl<R: ?Sized, S> Send for Grid<R, S>where
S: Send,
impl<R: ?Sized, S> Sync for Grid<R, S>where
S: Sync,
impl<R: ?Sized, S> Unpin for Grid<R, S>where
S: Unpin,
impl<R: ?Sized, S> UnwindSafe for Grid<R, S>where
S: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more