pub struct Grid<T: AsRef<str>> { /* private fields */ }
Expand description
Everything needed to format the cells with the grid options.
Implementations§
source§impl<T: AsRef<str>> Grid<T>
impl<T: AsRef<str>> Grid<T>
sourcepub fn new(cells: Vec<T>, options: GridOptions) -> Self
pub fn new(cells: Vec<T>, options: GridOptions) -> Self
Creates a new grid view with the given cells and options
Examples found in repository?
examples/basic.rs (lines 19-26)
16 17 18 19 20 21 22 23 24 25 26 27 28 29
fn main() {
let cells: Vec<_> = (0..48).map(|i| 2_isize.pow(i).to_string()).collect();
let grid = Grid::new(
cells,
GridOptions {
direction: Direction::TopToBottom,
filling: Filling::Text(" | ".into()),
width: 80,
},
);
println!("{}", grid);
}
More examples
examples/big.rs (lines 15-22)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
fn main() {
let mut n: u64 = 1234;
for _ in 0..50 {
let mut cells = Vec::new();
for _ in 0..10000 {
cells.push(n.to_string());
n = n.overflowing_pow(2).0 % 100000000;
}
let grid = Grid::new(
cells,
GridOptions {
direction: Direction::TopToBottom,
filling: Filling::Text(" | ".into()),
width: 80,
},
);
println!("{grid}");
}
}
sourcepub fn width(&self) -> usize
pub fn width(&self) -> usize
The number of terminal columns this display takes up, based on the separator width and the number and width of the columns.
sourcepub fn column_widths(&self) -> &[usize]
pub fn column_widths(&self) -> &[usize]
The width of each column
sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Returns whether this display takes up as many columns as were allotted to it.
It’s possible to construct tables that don’t actually use up all the columns that they could, such as when there are more columns than cells! In this case, a column would have a width of zero. This just checks for that.
Trait Implementations§
Auto Trait Implementations§
impl<T> RefUnwindSafe for Grid<T>where
T: RefUnwindSafe,
impl<T> Send for Grid<T>where
T: Send,
impl<T> Sync for Grid<T>where
T: Sync,
impl<T> Unpin for Grid<T>where
T: Unpin,
impl<T> UnwindSafe for Grid<T>where
T: 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