[][src]Trait text_grid::RowWrite

pub trait RowWrite: RowWriteCore {
    type Source;
    fn content<T: CellSource>(&mut self, f: impl FnOnce(Self::Source) -> T);

    fn group<C: CellSource>(&mut self, header: C) -> GroupGuard<Self, C> { ... }
fn column<T: CellSource>(
        &mut self,
        header: impl CellSource,
        f: impl FnOnce(Self::Source) -> T
    ) { ... }
fn map<F: Fn(Self::Source) -> R, R>(&mut self, f: F) -> Map<Self, F> { ... }
fn filter<F: Fn(&Self::Source) -> bool>(&mut self, f: F) -> Filter<Self, F> { ... }
fn filter_map<F: Fn(Self::Source) -> Option<R>, R>(
        &mut self,
        f: F
    ) -> FilterMap<Self, F> { ... }
fn with(&mut self, f: impl Fn(&mut Self)) { ... } }

Used to define column information.

  • Use column to create column.
  • Use group to create multi level header.
  • Use content to create shared header columns.

Associated Types

type Source

Loading content...

Required methods

fn content<T: CellSource>(&mut self, f: impl FnOnce(Self::Source) -> T)

Define column content. Used to create shared header column.

  • f : A function to obtain cell.

Examples

use text_grid::*;
struct RowData {
    a: u32,
    b_1: u32,
    b_2: u32,
}
impl RowSource for RowData {
    fn fmt_row<'a>(w: &mut impl RowWrite<Source = &'a Self>) {
        w.column("a", |s| s.a);
        w.group("b").with(|w| {
            w.content(|s| s.b_1);
            w.content(|_| " ");
            w.content(|s| s.b_2);
        });
    }
}

let mut g = Grid::new();
g.push_row(&RowData {
    a: 300,
    b_1: 10,
    b_2: 20,
});
g.push_row(&RowData {
    a: 300,
    b_1: 1,
    b_2: 500,
});

print!("{}", g);

Output:

  a  |   b    |
-----|--------|
 300 | 10  20 |
 300 |  1 500 |
Loading content...

Provided methods

fn group<C: CellSource>(&mut self, header: C) -> GroupGuard<Self, C>

Define column group. Used to create multi row header.

  • header : Column group header's cell. If horizontal alignment is not specified, it is set to the center.

Examples

use text_grid::*;
struct RowData {
    a: u32,
    b_1: u32,
    b_2: u32,
}
impl RowSource for RowData {
    fn fmt_row<'a>(w: &mut impl RowWrite<Source=&'a Self>) {
        w.column("a", |s| s.a);
        w.group("b").with(|w| {
            w.column("1", |s| s.b_1);
            w.column("2", |s| s.b_2);
        });
    }
}

let mut g = Grid::new();
g.push_row(&RowData {
    a: 300,
    b_1: 10,
    b_2: 20,
});
g.push_row(&RowData {
    a: 300,
    b_1: 1,
    b_2: 500,
});

Output:

  a  |    b     |
-----|----------|
     | 1  |  2  |
-----|----|-----|
 300 | 10 |  20 |
 300 |  1 | 500 |

fn column<T: CellSource>(
    &mut self,
    header: impl CellSource,
    f: impl FnOnce(Self::Source) -> T
)

Define column.

  • header : Column header's cell. If horizontal alignment is not specified, it is set to the center.
  • f : A function to obtain cell.

Examples

use text_grid::*;
struct RowData {
    a: u32,
    b: u32,
}
impl RowSource for RowData {
    fn fmt_row<'a>(w: &mut impl RowWrite<Source=&'a Self>) {
        w.column("a", |s| s.a);
        w.column("b", |s| s.b);
    }
}

let mut g = Grid::new();
g.push_row(&RowData { a: 300, b: 1 });
g.push_row(&RowData { a: 2, b: 200 });

print!("{}", g);

Output:

  a  |  b  |
-----|-----|
 300 |   1 |
   2 | 200 |

fn map<F: Fn(Self::Source) -> R, R>(&mut self, f: F) -> Map<Self, F>

Takes a closure and creates RowWrite whose source value was converted.

fn filter<F: Fn(&Self::Source) -> bool>(&mut self, f: F) -> Filter<Self, F>

Creates RowWrite which uses a closure to determine if an content should be outputed.

fn filter_map<F: Fn(Self::Source) -> Option<R>, R>(
    &mut self,
    f: F
) -> FilterMap<Self, F>

Creates RowWrite that both filters and maps.

fn with(&mut self, f: impl Fn(&mut Self))

Apply f to self.

Loading content...

Implementors

Loading content...