toml_to_table

Crates.iotoml_to_table
lib.rstoml_to_table
version0.5.0
sourcesrc
created_at2023-12-20 01:40:50.295906
updated_at2024-11-22 21:22:42.021538
descriptionA library for pretty print TOML as a table
homepagehttps://github.com/zhiburt/tabled
repositoryhttps://github.com/zhiburt/tabled
max_upload_size
id1074838
size80,963
Maxim Zhiburt (zhiburt)

documentation

https://docs.rs/ron_to_table

README

A library for converting toml 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 table and array via Orientation.

You'll find to examples for the modes bellow.

Usage

Add the library to a dependency list.

[dependencies]
toml_to_table = "0.1.0"
Example (embedded) Result
let data = r#"
[materials]
metal = { reflectivity = 1.0 }
plastic = { reflectivity = 0.5 }

[[entities]]
name = "hero"
material = "metal"

[[entities]]
name = "monster"
material = "plastic"
"#;

let scene = toml::from_str(data).unwrap();

let table = toml_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 toml_to_table::TomlTable;
use tabled::settings::Style;

let data = r#"
[materials]
metal = { reflectivity = 1.0 }
plastic = { reflectivity = 0.5 }

[[entities]]
name = "hero"
material = "metal"

[[entities]]
name = "monster"
material = "plastic"
"#;

let scene = toml::from_str(data).unwrap();
let table = TomlTable::new(&scene)
    .collapse()
    .with(Style::extended())
    .to_string();

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

cargo fmt