Struct term_grid::Grid

source ·
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>

source

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
Hide additional 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}");
    }
}
source

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.

source

pub fn row_count(&self) -> usize

The number of rows this display takes up.

source

pub fn column_widths(&self) -> &[usize]

The width of each column

source

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§

source§

impl<T: Debug + AsRef<str>> Debug for Grid<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: AsRef<str>> Display for Grid<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.