Struct text_grid::Grid

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

source

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>

source

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>

source

pub fn push(&mut self, source: &R)

Append a row to the bottom of the grid.

source

pub fn push_separator(&mut self)

Append a row separator to the bottom of the grid.

Trait Implementations§

source§

impl<R: ?Sized, S> Debug for Grid<R, S>

source§

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

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

impl<R: Cells + ?Sized> Default for Grid<R, DefaultCellsSchema<R>>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<R: ?Sized, S> Display for Grid<R, S>

source§

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

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

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)

Extends a collection with the contents of an iterator. Read more
source§

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)

🔬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>

source§

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)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

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<'a, R: Cells> FromIterator<&'a R> for Grid<R>

source§

fn from_iter<T: IntoIterator<Item = &'a R>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl<R: Cells> FromIterator<R> for Grid<R>

source§

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> 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.