Struct IterTable

Source
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>

Source

pub fn new(iter: I) -> Self
where I: IntoRecords,

Creates a new IterTable structure.

Source

pub fn with<O>(&mut self, option: O) -> &mut Self

With is a generic function which applies options to the IterTable.

Source

pub fn columns(&mut self, count_columns: usize) -> &mut Self

Limit a number of columns.

Source

pub fn rows(&mut self, count_rows: usize) -> &mut Self

Limit a number of rows.

Source

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.

Source

pub fn height(&mut self, size: usize) -> &mut Self

Set a height for each row.

Source

pub fn width(&mut self, size: usize) -> &mut Self

Set a width for each column.

Source

pub fn to_string(self) -> String
where I: IntoRecords, I::Cell: AsRef<str>,

Build a string.

We can’t implement std::string::ToString cause it does takes &self reference.

Source

pub fn build<W>(self, writer: W) -> Result<()>
where W: Write, I: IntoRecords, I::Cell: AsRef<str>,

Format table into io::Writer.

Source

pub fn fmt<W>(self, writer: W) -> Result
where W: Write, I: IntoRecords, I::Cell: AsRef<str>,

Format table into fmt::Writeer.

Trait Implementations§

Source§

impl<I: Clone> Clone for IterTable<I>

Source§

fn clone(&self) -> IterTable<I>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<I: Debug> Debug for IterTable<I>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> FromIterator<T> for IterTable<Vec<Vec<T::Item>>>
where T: IntoIterator, T::Item: AsRef<str>,

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<I: Hash> Hash for IterTable<I>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<I: Ord> Ord for IterTable<I>

Source§

fn cmp(&self, other: &IterTable<I>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<I: PartialEq> PartialEq for IterTable<I>

Source§

fn eq(&self, other: &IterTable<I>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<I: PartialOrd> PartialOrd for IterTable<I>

Source§

fn partial_cmp(&self, other: &IterTable<I>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<I: Eq> Eq for IterTable<I>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.