ron_to_table

Crates.ioron_to_table
lib.rsron_to_table
version0.3.0
sourcesrc
created_at2023-04-11 23:10:37.874086
updated_at2023-12-20 01:40:26.28271
descriptionA library for pretty print RON as a table
homepagehttps://github.com/zhiburt/tabled
repositoryhttps://github.com/zhiburt/tabled
max_upload_size
id836408
size77,012
Maxim Zhiburt (zhiburt)

documentation

https://docs.rs/ron_to_table

README

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 embeded 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 (embeded) 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 ║
╚═══════════╩═════════╩══════════════╩═════╝
Commit count: 1166

cargo fmt