5 releases (breaking)

0.5.0 Nov 22, 2024
0.4.0 Aug 5, 2024
0.3.0 Dec 20, 2023
0.2.0 Apr 23, 2023
0.1.0 Apr 11, 2023

#1424 in Text processing

Download history 15/week @ 2024-09-14 6/week @ 2024-09-21 13/week @ 2024-09-28 57/week @ 2024-11-16 74/week @ 2024-11-23 7/week @ 2024-11-30

138 downloads per month

MIT license

1MB
17K SLoC

A library for converting ron to a table.

It uses tabled as a rendering backend.

Get started

The library supports 2 modes for a table embedded and collapsed. It also provides with a list of options to modify the table, such as style, alignment, padding and more.

You can change an orientation of a map and sequence via Orientation.

You'll find to examples for the modes bellow.

Usage

Add the library to a dependency list.

[dependencies]
ron_to_table = "0.1.0"
Example (embedded) Result
let data = r#"Scene(
    materials: {
        "metal": (reflectivity: 1.0),
        "plastic": (reflectivity: 0.5),
    },
    entities: [
        (name: "hero", material: "metal"),
        (name: "monster", material: "plastic"),
    ],
)"#;

let scene = ron::from_str(data).unwrap();
let table = ron_to_table::to_string(&scene);

println!("{}", table);
+-------------+--------------------------------------------+
|  entities   | +----------------------------+             |
|             | | +------------+---------+   |             |
|             | | |  material  |  metal  |   |             |
|             | | +------------+---------+   |             |
|             | | |  name      |  hero   |   |             |
|             | | +------------+---------+   |             |
|             | +----------------------------+             |
|             | | +------------+-----------+ |             |
|             | | |  material  |  plastic  | |             |
|             | | +------------+-----------+ |             |
|             | | |  name      |  monster  | |             |
|             | | +------------+-----------+ |             |
|             | +----------------------------+             |
+-------------+--------------------------------------------+
|  materials  | +-----------+----------------------------+ |
|             | |  metal    | +----------------+-----+   | |
|             | |           | |  reflectivity  |  1  |   | |
|             | |           | +----------------+-----+   | |
|             | +-----------+----------------------------+ |
|             | |  plastic  | +----------------+-------+ | |
|             | |           | |  reflectivity  |  0.5  | | |
|             | |           | +----------------+-------+ | |
|             | +-----------+----------------------------+ |
+-------------+--------------------------------------------+
Example (collapsed) Result
use ron_to_table::RonTable;
use tabled::settings::Style;

let data = r#"Scene(
    materials: {
        "metal": (reflectivity: 1.0),
        "plastic": (reflectivity: 0.5),
    },
    entities: [
        (name: "hero", material: "metal"),
        (name: "monster", material: "plastic"),
    ],
)"#;

let scene = ron::from_str(data).unwrap();
let table = RonTable::default()
    .collapse()
    .with(Style::extended())
    .build(&scene);

println!("{table}");
╔═══════════╦══════════╦═══════════════════╗
║ entities  ║ material ║ metal             ║
║           ╠══════════╬═══════════════════╣
║           ║ name     ║ hero              ║
║           ╠══════════╬═══════════════════╣
║           ║ material ║ plastic           ║
║           ╠══════════╬═══════════════════╣
║           ║ name     ║ monster           ║
╠═══════════╬═════════╦╩═════════════╦═════╣
║ materials ║ metal   ║ reflectivity ║ 1   ║
║           ╠═════════╬══════════════╬═════╣
║           ║ plastic ║ reflectivity ║ 0.5 ║
╚═══════════╩═════════╩══════════════╩═════╝

Dependencies

~3.5MB
~69K SLoC