Struct text_grid::GridBuilder

source ·
pub struct GridBuilder {
    pub column_styles: Vec<ColumnStyle>,
    /* private fields */
}
Expand description

A builder used to create plain-text table.

§Examples

use text_grid::*;
let mut g = GridBuilder::new();
g.push(|b| {
    b.push(cell("name").right());
    b.push("type");
    b.push("value");
});
g.push_separator();
g.push(|b| {
    b.push(cell(String::from("X")).right());
    b.push("A");
    b.push(10);
});
g.push(|b| {
    b.push(cell("Y").right());
    b.push_with_colspan(cell("BBB").center(), 2);
});
assert_eq!(format!("\n{g}"), r#"
 name | type | value |
------|------|-------|
    X | A    |    10 |
    Y |     BBB      |
"#);

Fields§

§column_styles: Vec<ColumnStyle>

Implementations§

source§

impl GridBuilder

source

pub fn new() -> Self

Create a new GridBuilder.

source

pub fn from_iter_with_schema<T>( source: impl IntoIterator<Item = impl Borrow<T>>, schema: impl CellsSchema<Source = T> ) -> Self

source

pub fn push(&mut self, f: impl FnOnce(&mut RowBuilder<'_>))

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.

source

pub fn extend_header<T: ?Sized + Cells>(&mut self)

source

pub fn extend_header_with_schema<T: ?Sized>( &mut self, schema: impl CellsSchema<Source = T> )

source

pub fn push_body(&mut self, source: &impl Cells)

source

pub fn push_body_with_schema<T: ?Sized>( &mut self, source: &T, schema: impl CellsSchema<Source = T> )

source

pub fn extend_body(&mut self, source: impl IntoIterator<Item = impl Cells>)

source

pub fn extend_body_with_schema<T>( &mut self, source: impl IntoIterator<Item = impl Borrow<T>>, schema: impl CellsSchema<Source = T> )

Trait Implementations§

source§

impl Debug for GridBuilder

source§

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

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

impl Default for GridBuilder

source§

fn default() -> Self

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

impl Display for GridBuilder

source§

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

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

impl<T: Cells> FromIterator<T> for GridBuilder

source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

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.