//! This example demonstrates how to use the [write](TableFormatter::write) method of a [TableFormatter]. //! The [write](TableFormatter::write) and [debug_write](TableFormatter::debug_write) methods allow you to //! write a table result to a [Write] object rather than just stdout. (In this example, the Write object is //! just stdout, but you get the idea) //! //! Also note that this example uses a non-debug writing method. Tuples and arrays have default //! implementations for [DisplayTableRow](kitty_table::DisplayTableRow) whenever their members implement //! [Display](std::fmt::Display). For other types, this will need to be manually implemented, unlike //! [DebugTableRow](kitty_table::DebugTableRow) which can be `derive`d. use std::io::{stdout, Write}; use kitty_table::TableFormatter; pub fn main() { let table = TableFormatter::from_style(); let data = [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ]; let mut out = stdout().lock(); if let Err(err) = table.write(&mut out, data) { panic!("Failed to print table due to {}.", err.kind()); } let _ = out.flush(); } /* Expected result: ┏━━━┯━━━┯━━━┯━━━┓ ┃ 1 │ 0 │ 0 │ 0 ┃ ┠───┼───┼───┼───┨ ┃ 0 │ 1 │ 0 │ 0 ┃ ┠───┼───┼───┼───┨ ┃ 0 │ 0 │ 1 │ 0 ┃ ┠───┼───┼───┼───┨ ┃ 0 │ 0 │ 0 │ 1 ┃ ┗━━━┷━━━┷━━━┷━━━┛ */