GridPrinterBuilder

Struct GridPrinterBuilder 

Source
pub struct GridPrinterBuilder { /* private fields */ }
Expand description

A Builder to create/customize a GridPrinter instance

use grid_printer::GridPrinter;
use grid_printer::GridPrinterBuilder;
 
let rows = 3;
let cols = 3;
let printer: GridPrinter = GridPrinterBuilder::new(rows, cols)
    .col_spacing(4)
    .build();

Implementations§

Source§

impl GridPrinterBuilder

Source

pub fn new(rows: usize, cols: usize) -> Self

Source

pub fn col_spacing(self, col_spacing: usize) -> Self

Examples found in repository?
examples/cars.rs (line 14)
3fn main() {
4    let cars = vec![
5        vec!["Make", "Model", "Color", "Year", "Price", ],
6        vec!["Ford", "Pinto", "Green", "1978", "$750.00", ],
7        vec!["Toyota", "Tacoma", "Red", "2006", "$15,475.23", ],
8        vec!["Lamborghini", "Diablo", "Yellow", "2001", "$238,459.99", ],
9    ];
10
11    let rows = cars.len();
12    let cols = cars[0].len();
13    let printer = GridPrinter::builder(rows, cols)
14        .col_spacing(4)
15        .build();
16    printer.print(&cars);
17}
Source

pub fn col_styles( self, col_styles: Vec<Option<StyleOpt>>, ) -> Result<Self, GridPrinterErr>

Source

pub fn col_style( self, idx: usize, opt: StyleOpt, ) -> Result<Self, GridPrinterErr>

Examples found in repository?
examples/colors.rs (line 17)
5fn main() -> Result<(), Box<dyn Error>> {
6
7    let grid = vec![
8        vec![1, 2, 3, 4, ],
9        vec![5, 6, 7, 8, ],
10        vec![9, 10, 11, 12, ],
11    ];
12
13    let rows = grid.len();
14    let cols = grid[0].len();
15    
16    let printer = GridPrinter::builder(rows, cols)
17        .col_style(0, StyleOpt::new().fg(Fg::Magenta))?
18        .col_style(1, StyleOpt::new().fg(Fg::Black).bg(Bg::BrightYellow))?
19        .col_style(2, StyleOpt::new().sgr(Sgr::StrikeThrough))?
20        .col_style(3, StyleOpt::new().fg(Fg::Cyan))?
21        .build();
22    printer.print(&grid);
23
24    Ok(())
25}
Source

pub fn build(self) -> GridPrinter

Examples found in repository?
examples/cars.rs (line 15)
3fn main() {
4    let cars = vec![
5        vec!["Make", "Model", "Color", "Year", "Price", ],
6        vec!["Ford", "Pinto", "Green", "1978", "$750.00", ],
7        vec!["Toyota", "Tacoma", "Red", "2006", "$15,475.23", ],
8        vec!["Lamborghini", "Diablo", "Yellow", "2001", "$238,459.99", ],
9    ];
10
11    let rows = cars.len();
12    let cols = cars[0].len();
13    let printer = GridPrinter::builder(rows, cols)
14        .col_spacing(4)
15        .build();
16    printer.print(&cars);
17}
More examples
Hide additional examples
examples/colors.rs (line 21)
5fn main() -> Result<(), Box<dyn Error>> {
6
7    let grid = vec![
8        vec![1, 2, 3, 4, ],
9        vec![5, 6, 7, 8, ],
10        vec![9, 10, 11, 12, ],
11    ];
12
13    let rows = grid.len();
14    let cols = grid[0].len();
15    
16    let printer = GridPrinter::builder(rows, cols)
17        .col_style(0, StyleOpt::new().fg(Fg::Magenta))?
18        .col_style(1, StyleOpt::new().fg(Fg::Black).bg(Bg::BrightYellow))?
19        .col_style(2, StyleOpt::new().sgr(Sgr::StrikeThrough))?
20        .col_style(3, StyleOpt::new().fg(Fg::Cyan))?
21        .build();
22    printer.print(&grid);
23
24    Ok(())
25}

Trait Implementations§

Source§

impl Debug for GridPrinterBuilder

Source§

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

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

impl Default for GridPrinterBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.