simple_tables/lib.rs
1//! The simple tables crate allows you to easily create table structures.
2//!
3//! # Getting started
4//! You can use the macros [`table_row`](crate::macros::table_row) and [`table`](crate::macros::table)
5//! to make a new table with the row structure defined by your table rows.
6//!
7//! **Example**
8//! ```rust
9//! # use simple_tables::macros::{table_row, table};
10//!
11//! #[table_row]
12//! struct MyTableRow {
13//! id: u32,
14//! name: String,
15//! email: String,
16//! address: String
17//! }
18//!
19//! #[table(rows = MyTableRow)]
20//! struct MyTable {}
21//! ```
22//!
23//! # Examples
24//! ## Printing out a table
25//!
26//! You can use the `to_string()` method to convert a table to a formatted text table
27//! and then print it out.
28//!
29//! ```rust
30//! # use simple_tables::Table;
31//! # use simple_tables::macros::{table_row, table};
32//! #
33//! # #[table_row]
34//! # struct MyTableRow {
35//! # id: u32,
36//! # name: String,
37//! # email: String,
38//! # address: String
39//! # }
40//! #
41//! # #[table(rows = MyTableRow)]
42//! # struct MyTable {}
43//!
44//! let rows: Vec<MyTableRow> = vec![
45//! MyTableRow{ id: 0, name: "David Bowie".to_string(), email: "david@bowie.com".to_string(), address: "England".to_string()},
46//! MyTableRow{ id: 1, name: "David Gilmour".to_string(), email: "david@gilmour.com".to_string(), address: "England".to_string()},
47//! MyTableRow{ id: 2, name: "Opeth".to_string(), email: "info@opeth.com".to_string(), address: "Sweden".to_string()},
48//! MyTableRow{ id: 3, name: "The Beatles".to_string(), email: "info@beatles.com".to_string(), address: "England".to_string()}
49//! ];
50//!
51//! let table = MyTable::from_vec(&rows);
52//! let s = table.to_string();
53//! println!("{}", s);
54//! ```
55//!
56//! The output will be:
57//! ```bash
58//! +----+---------------+-------------------+---------+
59//! | id | name | email | address |
60//! +====+===============+===================+=========+
61//! | 0 | David Bowie | david@bowie.com | England |
62//! +----+---------------+-------------------+---------+
63//! | 1 | David Gilmour | david@gilmour.com | England |
64//! +----+---------------+-------------------+---------+
65//! | 2 | Opeth | info@opeth.com | Sweden |
66//! +----+---------------+-------------------+---------+
67//! | 3 | The Beatles | info@beatles.com | England |
68//! +----+---------------+-------------------+---------+
69//! ```
70//!
71//! More examples can be found on [GitHub](https://github.com/jomy10/simple_tables).
72//!
73//! # Traits
74//! - [Table](crate::Table)
75//! - [TableRow](crate::TableRow)
76//! - [IdTable](crate::IdTable)
77//!
78//! # Macros
79//! - [table_row](crate::macros::table_row)
80//! - [table](crate::macros::table)
81
82
83// Core libraries
84pub extern crate simple_tables_core as core;
85pub extern crate simple_tables_derive as derive;
86
87// Library structure
88pub mod macros {
89 pub use derive::table_row as table_row;
90 pub use derive::table as table;
91}
92
93pub use core::Table;
94pub use core::TableRow;
95pub use core::IdTable;
96
97pub use core::error;