tabled/table_iterator_ext.rs
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
use papergrid::records::{cell_info::CellInfo, vec_records::VecRecords};
use crate::{Table, Tabled};
/// A trait for [`IntoIterator`] whose Item type is bound to [`Tabled`].
/// Any type implements [`IntoIterator`] can call this function directly
///
/// ```rust
/// use tabled::{TableIteratorExt, Style};
///
/// let strings: &[&str] = &["Hello", "World"];
///
/// let mut table = strings.table();
/// table.with(Style::psql());
///
/// println!("{}", table);
/// ```
pub trait TableIteratorExt {
/// A underline [`Records`]
///
/// [`Records`]: crate::papergrid::records::Records
type Records;
/// Returns a [`Table`] instance from a given type
fn table(self) -> Table<Self::Records>;
}
impl<I, T> TableIteratorExt for I
where
I: IntoIterator<Item = T>,
T: Tabled,
{
type Records = VecRecords<CellInfo<'static>>;
fn table(self) -> Table<Self::Records> {
Table::new(self)
}
}