//! This example shows how you can quickly set up a table printer //! for your datatype. use kitty_table::{DebugTableRow, DefaultTableStyle, TableFormatter}; #[derive(DefaultTableStyle, DebugTableRow)] pub struct MyDictionaryStruct<'src> { name: &'src str, age: u32, adult: bool, } #[derive(DefaultTableStyle, DebugTableRow)] pub struct MyTupleStruct(i32, i32, i32); pub fn main() { dictionary_struct(); tuple_struct(); } fn dictionary_struct() { // Create a table using the default formatter for MyDictionaryStruct. // This default formatter was created by deriving DefaultTableStyle above. let table = TableFormatter::from_style(); // Don't format this into a million lines please it's fine like this #[rustfmt::skip] let data = [ MyDictionaryStruct { name: "Susan", age: 42, adult: true }, MyDictionaryStruct { name: "Ashli", age: 19, adult: true }, MyDictionaryStruct { name: "Groot", age: 5, adult: false }, MyDictionaryStruct { name: "Henry", age: 53, adult: true }, MyDictionaryStruct { name: "Whatever", age: 17, adult: false }, ]; // Print our results. We are able to use MyDictionaryStruct here // because we derived DebugTableRow earlier. let _ = table.debug_print(data); } fn tuple_struct() { // Create a table using the default formatter for MyTupleStruct. This // default formatter was created by deriving DefaultTableStyle above. let table = TableFormatter::from_style(); let data = [ MyTupleStruct(7, -10, -3), MyTupleStruct(6, -7, -1), MyTupleStruct(5, -4, 1), MyTupleStruct(4, -1, 3), MyTupleStruct(3, 2, 5), MyTupleStruct(2, 5, 7), MyTupleStruct(1, 8, 9), MyTupleStruct(0, 11, 11), MyTupleStruct(-1, 14, 13), MyTupleStruct(-2, 17, 15), ]; // Print our results. We are able to use MyTupleStruct here // because we derived DebugTableRow earlier. let _ = table.debug_print(data); } /* Expected result: ┏━━━━━━━━━━━━┳━━━━━┳━━━━━━━┓ ┃ name ┃ age ┃ adult ┃ ┣━━━━━━━━━━━━╇━━━━━╇━━━━━━━┫ ┃ "Susan" │ 42 │ true ┃ ┠────────────┼─────┼───────┨ ┃ "Ashli" │ 19 │ true ┃ ┠────────────┼─────┼───────┨ ┃ "Groot" │ 5 │ false ┃ ┠────────────┼─────┼───────┨ ┃ "Henry" │ 53 │ true ┃ ┠────────────┼─────┼───────┨ ┃ "Whatever" │ 17 │ false ┃ ┗━━━━━━━━━━━━┷━━━━━┷━━━━━━━┛ ┏━━━━┯━━━━━┯━━━━┓ ┃ 7 │ -10 │ -3 ┃ ┠────┼─────┼────┨ ┃ 6 │ -7 │ -1 ┃ ┠────┼─────┼────┨ ┃ 5 │ -4 │ 1 ┃ ┠────┼─────┼────┨ ┃ 4 │ -1 │ 3 ┃ ┠────┼─────┼────┨ ┃ 3 │ 2 │ 5 ┃ ┠────┼─────┼────┨ ┃ 2 │ 5 │ 7 ┃ ┠────┼─────┼────┨ ┃ 1 │ 8 │ 9 ┃ ┠────┼─────┼────┨ ┃ 0 │ 11 │ 11 ┃ ┠────┼─────┼────┨ ┃ -1 │ 14 │ 13 ┃ ┠────┼─────┼────┨ ┃ -2 │ 17 │ 15 ┃ ┗━━━━┷━━━━━┷━━━━┛ */