tabled/macros/
row.rs

1/// Creates a [`Table`] with [`Display`] arguments nested within.
2///
3/// The macros allows several tables to be displayed horizontally.
4///
5/// Companion to [`col!`].
6///
7/// # Examples
8/// ```rust,no_run
9/// # use tabled::{row, col, Table};
10/// # let (table1, table2, table3) = (Table::new(&[String::new()]), Table::new(&[String::new()]), Table::new(&[String::new()]));
11/// let new_table = row![table1, table2];
12/// let new_table_of_clones = row![table1; 3];
13/// let rows_and_columns = row![
14///     table1,
15///     col![table2, table3]
16/// ];
17/// ```
18///
19/// [`col!`]: crate::col
20/// [`Table`]: crate::Table
21/// [`Display`]: std::fmt::Display
22#[macro_export]
23#[cfg_attr(docsrs, doc(cfg(feature = "macros")))]
24macro_rules! row {
25    // Horizontal Display
26    ( $($table:expr), * $(,)? ) => {{
27        let mut builder = $crate::builder::Builder::default();
28
29        builder.add_record([ $($table.to_string(),)* ]);
30
31        builder.build()
32    }};
33
34    // Duplicate single item
35    ( $table:expr; $N:expr) => {{
36        let mut builder = $crate::builder::Builder::default();
37
38        let duplicates = vec![$table.to_string(); $N];
39        builder.add_record(duplicates);
40
41        builder.build()
42    }};
43}