Struct text_grid::GridBuf

source ·
pub struct GridBuf { /* private fields */ }
Expand description

A builder used to create plain-text table.

Examples

use text_grid::*;
let mut g = GridBuf::new();
{
    let mut row = g.push_row();
    row.push(cell("name").right());
    row.push("type");
    row.push("value");
}
g.push_separator();
{
    let mut row = g.push_row();
    row.push(cell(String::from("X")).right());
    row.push("A");
    row.push(10);
}
{
    let mut row = g.push_row();
    row.push(cell("Y").right());
    row.push_with_colspan(cell("BBB").center(), 2);
}

print!("{}", g);

Output

 name | type | value |
------|------|-------|
    X | A    |    10 |
    Y |     BBB      |

Implementations§

Create a new GridBuf.

Set column separator’s visibility.

separators[0] indicate visibility of the right side of the leftmost column.

Examples
use text_grid::*;
let mut g = GridBuf::new();
{
    let mut row = g.push_row();
    row.push("A");
    row.push("B");
    row.push("C");
}
{
    let mut row = g.push_row();
    row.push("AAA");
    row.push("BBB");
    row.push("CCC");
}
g.set_column_separators(vec![true, true]);
println!("{:?}", vec![true, true]);
println!("{}", g);

g.set_column_separators(vec![false, true]);
println!("{:?}", vec![false, true]);
println!("{}", g);
Output
[true, true]
 A   | B   | C   |
 AAA | BBB | CCC |

[false, true]
 A  B   | C   |
 AAABBB | CCC |  

Append a row to the bottom of grid.

Append a row separator to the bottom of grid.

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.