6 releases (breaking)

0.7.0 Feb 8, 2025
0.6.0 Nov 22, 2024
0.5.0 Aug 5, 2024
0.4.0 Dec 20, 2023
0.2.0 Apr 11, 2023

#1053 in Text processing

Download history 13/week @ 2024-11-02 44/week @ 2024-11-09 68/week @ 2024-11-16 96/week @ 2024-11-23 16/week @ 2024-11-30 33/week @ 2024-12-07 10/week @ 2024-12-14 23/week @ 2025-01-04 23/week @ 2025-01-11 74/week @ 2025-01-18 30/week @ 2025-01-25 83/week @ 2025-02-01 183/week @ 2025-02-08

372 downloads per month
Used in albion_terminal_rpg

MIT license

1MB
16K SLoC

A library for converting csv to a table.

It uses tabled as a rendering backend.

Install

Add the library to a dependency list.

[dependencies]
csv_to_table = "0.3"

Usage

There's 2 approaches the library provides.

  • In memory approach; where we load CSV into memory and then construct a table.
  • Sniffing a csv; so the used memory will be limited.
  • Setting your constrains so no memory will be used.
Example of in memory approach
fn main() {
    let syscalls = "\
        0,INDIR,,\"int sys_syscall(int number, ...)\"\n\
        1,STD,,\"void sys_exit(int rval)\"\n\
        2,STD,,\"int sys_fork(void)\"\n\
        3,STD,NOLOCK,\"ssize_t sys_read(int fd, void *buf, size_t nbyte)\"\n\
        4,STD,NOLOCK,\"ssize_t sys_write(int fd, const void *buf, size_t nbyte)\""; 

    let table = csv_to_table::from_reader(syscalls.as_bytes()).unwrap();

    println!("{table}")
}
Result
+---+-------+--------+----------------------------------------------------------+
| 0 | INDIR |        | int sys_syscall(int number, ...)                         |
+---+-------+--------+----------------------------------------------------------+
| 1 | STD   |        | void sys_exit(int rval)                                  |
+---+-------+--------+----------------------------------------------------------+
| 2 | STD   |        | int sys_fork(void)                                       |
+---+-------+--------+----------------------------------------------------------+
| 3 | STD   | NOLOCK | ssize_t sys_read(int fd, void *buf, size_t nbyte)        |
+---+-------+--------+----------------------------------------------------------+
| 4 | STD   | NOLOCK | ssize_t sys_write(int fd, const void *buf, size_t nbyte) |
+---+-------+--------+----------------------------------------------------------+
Example of sniffing approach
fn main() {
    let syscalls = "\
        0,INDIR,,\"int sys_syscall(int number, ...)\"\n\
        1,STD,,\"void sys_exit(int rval)\"\n\
        2,STD,,\"int sys_fork(void)\"\n\
        3,STD,NOLOCK,\"ssize_t sys_read(int fd, void *buf, size_t nbyte)\"\n\
        4,STD,NOLOCK,\"ssize_t sys_write(int fd, const void *buf, size_t nbyte)\"";

    let table = csv_to_table::iter::from_reader(syscalls.as_bytes()).sniff(3);

    table.build(std::io::stdout()).unwrap();
}
Result
+---+-------+--+----------------------------------+
| 0 | INDIR |  | int sys_syscall(int number, ...) |
+---+-------+--+----------------------------------+
| 1 | STD   |  | void sys_exit(int rval)          |
+---+-------+--+----------------------------------+
| 2 | STD   |  | int sys_fork(void)               |
+---+-------+--+----------------------------------+
| 3 | STD   |  | ssize_t sys_read(int fd, void *b |
+---+-------+--+----------------------------------+
| 4 | STD   |  | ssize_t sys_write(int fd, const  |
+---+-------+--+----------------------------------+
Notice that the last 2 rows are truncated.

Dependencies

~3.5MB
~53K SLoC