#print #array #dimensional #stdout #printing #api #vec

grid-printer

一个方便打印格式化二维数组的API

2个版本

0.1.1 2021年6月1日
0.1.0 2021年5月25日

#5 in #dimensional


2个crate中使用(通过hacker-news

MIT/Apache

18KB
318

grid-printer

一个将二维数组轻松打印到标准输出的API。

示例
let cars = vec![
    vec!["Make", "Model", "Color", "Year", "Price", ],
    vec!["Ford", "Pinto", "Green", "1978", "$750.00", ],
    vec!["Toyota", "Tacoma", "Red", "2006", "$15,475.23", ],
    vec!["Lamborghini", "Diablo", "Yellow", "2001", "$238,459.99", ],
];

let rows = cars.len();
let cols = cars[0].len();
let printer = GridPrinter::builder(rows, cols)
    .col_spacing(4)
    .build();
printer.print(&cars);
输出
Make           Model     Color     Year    Price
Ford           Pinto     Green     1978    $750.00
Toyota         Tacoma    Red       2006    $15,475.23
Lamborghini    Diablo    Yellow    2001    $238,459.99

lib.rs:

一个将二维数组轻松打印到标准输出的API。

示例

use grid_printer::GridPrinter;

let cars = vec![
    vec!["Make", "Model", "Color", "Year", "Price", ],
    vec!["Ford", "Pinto", "Green", "1978", "$750.00", ],
    vec!["Toyota", "Tacoma", "Red", "2006", "$15,475.23", ],
    vec!["Lamborghini", "Diablo", "Yellow", "2001", "$238,459.99", ],
];

let rows = cars.len();
let cols = cars[0].len();
let printer = GridPrinter::builder(rows, cols)
    .col_spacing(4)
    .build();
printer.print(&cars);

输出

Make           Model     Color     Year    Price
Ford           Pinto     Green     1978    $750.00
Toyota         Tacoma    Red       2006    $15,475.23
Lamborghini    Diablo    Yellow    2001    $238,459.99

无运行时依赖