1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//! Builder module provides a [`Builder`] type which helps building
//! a [`Table`] dynamically.
//!
//! It also contains [`IndexBuilder`] which can help to build a table with index.
//!
//! # Examples
//!
//! Here's an example of [`IndexBuilder`] usage
//!
//! use tabled::{Table, Tabled, settings::Style};
//!
//! #[derive(Tabled)]
//! struct Mission {
//! name: &'static str,
//! #[tabled(inline)]
//! status: Status,
//! }
//!
//! #[derive(Tabled)]
//! enum Status {
//! Complete,
//! Started,
//! Ready,
//! Unknown,
//! }
//!
//! let data = [
//! Mission { name: "Algebra", status: Status::Unknown },
//! Mission { name: "Apolo", status: Status::Complete },
//! ];
//!
//! let mut builder = Table::builder(&data)
//! .index()
//! .column(0)
//! .name(None)
//! .transpose();
//!
//! let mut table = builder.build();
//! table.with(Style::modern());
//!
//! println!("{}", table);
//!
//! assert_eq!(
//! table.to_string(),
//! concat!(
//! "┌──────────┬─────────┬───────┐\n",
//! "│ │ Algebra │ Apolo │\n",
//! "├──────────┼─────────┼───────┤\n",
//! "│ Complete │ │ + │\n",
//! "├──────────┼─────────┼───────┤\n",
//! "│ Started │ │ │\n",
//! "├──────────┼─────────┼───────┤\n",
//! "│ Ready │ │ │\n",
//! "├──────────┼─────────┼───────┤\n",
//! "│ Unknown │ + │ │\n",
//! "└──────────┴─────────┴───────┘",
//! ),
//! )
//! ```
//!
//! Example when we don't want to show empty data of enum where not all variants are used.
//!
//! use tabled::{Table, Tabled, settings::Style};
//!
//! #[derive(Tabled)]
//! enum Status {
//! #[tabled(inline)]
//! Complete {
//! started_timestamp: usize,
//! finihsed_timestamp: usize,
//! },
//! #[tabled(inline)]
//! Started {
//! timestamp: usize,
//! },
//! Ready,
//! Unknown,
//! }
//!
//! let data = [
//! Status::Unknown,
//! Status::Complete { started_timestamp: 123, finihsed_timestamp: 234 },
//! ];
//!
//! let table = Table::new(data)
//! .with(Style::modern())
//! .to_string();
//!
//! println!("{}", table);
//!
//! assert_eq!(
//! table,
//! concat!(
//! "┌───────────────────┬────────────────────┬───────────┬───────┬─────────┐\n",
//! "│ started_timestamp │ finihsed_timestamp │ timestamp │ Ready │ Unknown │\n",
//! "├───────────────────┼────────────────────┼───────────┼───────┼─────────┤\n",
//! "│ │ │ │ │ + │\n",
//! "├───────────────────┼────────────────────┼───────────┼───────┼─────────┤\n",
//! "│ 123 │ 234 │ │ │ │\n",
//! "└───────────────────┴────────────────────┴───────────┴───────┴─────────┘",
//! ),
//! )
//! ```
//!
//! [`Table`]: crate::Table
pub use IndexBuilder;
pub use Builder;