pub struct IterTable<I> { /* private fields */ }
Expand description
A table which consumes an IntoRecords
iterator.
To be able to build table we need a dimensions.
If no width and count_columns is set, IterTable
will sniff the records, by
keeping a number of rows buffered (You can set the number via IterTable::sniff
).
In contrast to Table
IterTable
does no allocations but it consumes an iterator.
It’s useful when you don’t want to re/allocate a buffer for your data.
§Example
use tabled::{grid::records::IterRecords, tables::IterTable};
use tabled::assert::assert_table;
let data = vec![
vec!["First", "row"],
vec!["Second", "row"],
vec!["Third", "big \n multiline row"],
];
let records = IterRecords::new(data, 2, Some(2));
let mut table = IterTable::new(records);
table.sniff(1);
// notice because of sniff 1 we have all rows after the first one being truncated
assert_table!(
table.to_string(),
"+-------+-----+"
"| First | row |"
"+-------+-----+"
"| Secon | row |"
"+-------+-----+"
"| Third | big |"
"+-------+-----+"
);
Implementations§
Source§impl<I> IterTable<I>
impl<I> IterTable<I>
Sourcepub fn new(iter: I) -> Selfwhere
I: IntoRecords,
pub fn new(iter: I) -> Selfwhere
I: IntoRecords,
Creates a new IterTable
structure.
Sourcepub fn with<O>(&mut self, option: O) -> &mut Self
pub fn with<O>(&mut self, option: O) -> &mut Self
With is a generic function which applies options to the IterTable
.
Sourcepub fn sniff(&mut self, count: usize) -> &mut Self
pub fn sniff(&mut self, count: usize) -> &mut Self
Limit an amount of rows will be read for dimension estimations.
By default it’s 1000.
Sourcepub fn to_string(self) -> String
pub fn to_string(self) -> String
Build a string.
We can’t implement std::string::ToString
cause it does takes &self
reference.
Sourcepub fn fmt<W>(self, writer: W) -> Result
pub fn fmt<W>(self, writer: W) -> Result
Format table into fmt::Writeer.
Trait Implementations§
Source§impl<T> FromIterator<T> for IterTable<Vec<Vec<T::Item>>>
impl<T> FromIterator<T> for IterTable<Vec<Vec<T::Item>>>
Source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Creates a value from an iterator. Read more
Source§impl<I: Ord> Ord for IterTable<I>
impl<I: Ord> Ord for IterTable<I>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<I: PartialOrd> PartialOrd for IterTable<I>
impl<I: PartialOrd> PartialOrd for IterTable<I>
impl<I: Eq> Eq for IterTable<I>
impl<I> StructuralPartialEq for IterTable<I>
Auto Trait Implementations§
impl<I> Freeze for IterTable<I>where
I: Freeze,
impl<I> RefUnwindSafe for IterTable<I>where
I: RefUnwindSafe,
impl<I> Send for IterTable<I>where
I: Send,
impl<I> Sync for IterTable<I>where
I: Sync,
impl<I> Unpin for IterTable<I>where
I: Unpin,
impl<I> UnwindSafe for IterTable<I>where
I: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more