From ef24de24a82fe681581cc130f342363c47c0969a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 7 Jun 2024 07:48:48 +0200 Subject: Merging upstream version 1.75.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/tabled/src/macros/col.rs | 50 +++++++++++++++++++++++++++++++++++++++++ vendor/tabled/src/macros/mod.rs | 6 +++++ vendor/tabled/src/macros/row.rs | 44 ++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 vendor/tabled/src/macros/col.rs create mode 100644 vendor/tabled/src/macros/mod.rs create mode 100644 vendor/tabled/src/macros/row.rs (limited to 'vendor/tabled/src/macros') diff --git a/vendor/tabled/src/macros/col.rs b/vendor/tabled/src/macros/col.rs new file mode 100644 index 000000000..1fd67de8a --- /dev/null +++ b/vendor/tabled/src/macros/col.rs @@ -0,0 +1,50 @@ +/// Creates a [`Table`] with [`Display`] arguments nested within. +/// +/// The macros allows several tables to be displayed vertically. +/// +/// Companion to [`row!`]. +/// +/// # Examples +/// ```rust,no_run +/// # use tabled::{row, col, Table}; +/// # let (table1, table2, table3) = (Table::new(&[String::new()]), Table::new(&[String::new()]), Table::new(&[String::new()])); +/// let new_table = col![table1, table2]; +/// let new_table_of_clones = col![table1; 3]; +/// let columns_and_rows = col![ +/// table1, +/// row![table2, table3] +/// ]; +/// ``` +/// +/// [`row!`]: crate::row +/// [`Table`]: crate::Table +/// [`Display`]: std::fmt::Display +#[macro_export] +#[cfg_attr(docsrs, doc(cfg(feature = "macros")))] +macro_rules! col { + // Vertical + ( $($table:expr), * $(,)? ) => {{ + let mut builder = $crate::builder::Builder::default(); + + $( + builder.push_record([$table.to_string()]); + )* + + builder.build() + }}; + + // Duplicate single item + ( $table:expr; $N:expr) => {{ + let mut builder = $crate::builder::Builder::default(); + + let n = $N; + if n > 0 { + let t = $table.to_string(); + for _ in 0..$N { + builder.push_record([t.clone()]); + } + } + + builder.build() + }}; +} diff --git a/vendor/tabled/src/macros/mod.rs b/vendor/tabled/src/macros/mod.rs new file mode 100644 index 000000000..7db0a9caa --- /dev/null +++ b/vendor/tabled/src/macros/mod.rs @@ -0,0 +1,6 @@ +//! This module contains macro functions for dynamic [`Table`] construction. +//! +//! [`Table`]: crate::Table + +mod col; +mod row; diff --git a/vendor/tabled/src/macros/row.rs b/vendor/tabled/src/macros/row.rs new file mode 100644 index 000000000..23775b90d --- /dev/null +++ b/vendor/tabled/src/macros/row.rs @@ -0,0 +1,44 @@ +/// Creates a [`Table`] with [`Display`] arguments nested within. +/// +/// The macros allows several tables to be displayed horizontally. +/// +/// Companion to [`col!`]. +/// +/// # Examples +/// ```rust,no_run +/// # use tabled::{row, col, Table}; +/// # let (table1, table2, table3) = (Table::new(&[String::new()]), Table::new(&[String::new()]), Table::new(&[String::new()])); +/// let new_table = row![table1, table2]; +/// let new_table_of_clones = row![table1; 3]; +/// let rows_and_columns = row![ +/// table1, +/// col![table2, table3] +/// ]; +/// ``` +/// +/// [`col!`]: crate::col +/// [`Table`]: crate::Table +/// [`Display`]: std::fmt::Display +#[macro_export] +#[cfg_attr(docsrs, doc(cfg(feature = "macros")))] +macro_rules! row { + // Horizontal Display + ( $($table:expr), * $(,)? ) => {{ + let mut builder = $crate::builder::Builder::default(); + + let record = [ $($table.to_string(),)* ]; + builder.push_record(record); + + builder.build() + }}; + + // Duplicate single item + ( $table:expr; $N:expr) => {{ + let mut builder = $crate::builder::Builder::default(); + + let duplicates = vec![$table.to_string(); $N]; + builder.push_record(duplicates); + + builder.build() + }}; +} -- cgit v1.2.3