3 releases (breaking)

new 0.5.0 Nov 22, 2024
0.4.0 Aug 5, 2024
0.3.0 Dec 20, 2023

#1970 in Text processing

Download history 8/week @ 2024-07-26 113/week @ 2024-08-02 9/week @ 2024-08-09 10/week @ 2024-09-13 7/week @ 2024-09-20 9/week @ 2024-09-27 1/week @ 2024-10-04

144 downloads per month

MIT license

795KB
16K SLoC

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 ║
╚═══════════╩═════════╩══════════════╩═════╝

Dependencies

~2.5MB
~49K SLoC