Crate ron_to_table
source ·Expand description
The library creates pretty table out of a ron
object.
The are 2 types of tables you can create. 1. Embeded (default) 2. Collapsed
Examples
Embeded table.
let data = r#"GameConfig(
window_size: (800, 600),
window_title: "PAC-MAN",
fullscreen: false,
mouse_sensitivity: 1.4,
key_bindings: {
"up": Up,
"down": Down,
"left": Left,
"right": Right,
},
difficulty_options: (
start_difficulty: Easy,
adaptive: false,
),
)"#;
let scene = ron::from_str(data).unwrap();
assert_eq!(
ron_to_table::to_string(&scene),
"+----------------------+----------------------------------+\n\
| difficulty_options | +--------------------+---------+ |\n\
| | | adaptive | false | |\n\
| | +--------------------+---------+ |\n\
| | | start_difficulty | | |\n\
| | +--------------------+---------+ |\n\
+----------------------+----------------------------------+\n\
| fullscreen | false |\n\
+----------------------+----------------------------------+\n\
| key_bindings | +---------+--+ |\n\
| | | down | | |\n\
| | +---------+--+ |\n\
| | | left | | |\n\
| | +---------+--+ |\n\
| | | right | | |\n\
| | +---------+--+ |\n\
| | | up | | |\n\
| | +---------+--+ |\n\
+----------------------+----------------------------------+\n\
| mouse_sensitivity | 1.4 |\n\
+----------------------+----------------------------------+\n\
| window_size | +-------+ |\n\
| | | 800 | |\n\
| | +-------+ |\n\
| | | 600 | |\n\
| | +-------+ |\n\
+----------------------+----------------------------------+\n\
| window_title | PAC-MAN |\n\
+----------------------+----------------------------------+"
);
Collapsed table.
let data = r#"GameConfig(
window_size: (800, 600),
window_title: "PAC-MAN",
fullscreen: false,
mouse_sensitivity: 1.4,
key_bindings: {
"up": Up,
"down": Down,
"left": Left,
"right": Right,
},
difficulty_options: (
start_difficulty: Easy,
adaptive: false,
),
)"#;
let scene = ron::from_str(data).unwrap();
use ron_to_table::RonTable;
use tabled::settings::Style;
let table = RonTable::default().collapse().with(Style::modern()).build(&scene);
assert_eq!(
table,
"┌────────────────────┬──────────────────┬───────┐\n\
│ difficulty_options │ adaptive │ false │\n\
│ ├──────────────────┼───────┤\n\
│ │ start_difficulty │ │\n\
├────────────────────┼──────────────────┴───────┤\n\
│ fullscreen │ false │\n\
├────────────────────┼───────┬──────────────────┤\n\
│ key_bindings │ down │ │\n\
│ ├───────┼──────────────────┤\n\
│ │ left │ │\n\
│ ├───────┼──────────────────┤\n\
│ │ right │ │\n\
│ ├───────┼──────────────────┤\n\
│ │ up │ │\n\
├────────────────────┼───────┴──────────────────┤\n\
│ mouse_sensitivity │ 1.4 │\n\
├────────────────────┼──────────────────────────┤\n\
│ window_size │ 800 │\n\
│ ├──────────────────────────┤\n\
│ │ 600 │\n\
├────────────────────┼──────────────────────────┤\n\
│ window_title │ PAC-MAN │\n\
└────────────────────┴──────────────────────────┘",
);
Structs
- Converter of
Value
to a table, with a set of configurations.
Enums
- The structure represents a table mode for a given entity, either it will be rendered vertically or horizontally.
Functions
- The function converts a given
Value
to a pretty table.