Struct prettytable::Table

source ·
pub struct Table { /* private fields */ }
Expand description

An owned printable table

Implementations§

source§

impl Table

source

pub fn from_csv_string(csv_s: &str) -> Result<Self>

Create a table from a CSV string

For more customisability use from_csv()

source

pub fn from_csv_file<P: AsRef<Path>>(csv_p: P) -> Result<Self>

Create a table from a CSV file

For more customisability use from_csv()

source

pub fn from_csv<R: Read>(reader: &mut Reader<R>) -> Self

Create a table from a CSV reader

source

pub fn to_csv<W: Write>(&self, w: W) -> Result<Writer<W>>

Write the table to the specified writer.

source

pub fn to_csv_writer<W: Write>(&self, writer: Writer<W>) -> Result<Writer<W>>

Write the table to the specified writer.

This allows for format customisation.

source§

impl Table

source

pub fn new() -> Table

Create an empty table

source

pub fn init(rows: Vec<Row>) -> Table

Create a table initialized with rows

source

pub fn set_format(&mut self, format: TableFormat)

Change the table format. Eg : Separators

source

pub fn get_format(&mut self) -> &mut TableFormat

Get a mutable reference to the internal format

source

pub fn get_column_num(&self) -> usize

👎Deprecated since 0.8.0: Will become private in future release. See issue #87

Compute and return the number of column

source

pub fn len(&self) -> usize

Get the number of rows

source

pub fn is_empty(&self) -> bool

Check if the table is empty

source

pub fn set_titles(&mut self, titles: Row)

Set the optional title lines

source

pub fn unset_titles(&mut self)

Unset the title line

source

pub fn get_mut_row(&mut self, row: usize) -> Option<&mut Row>

Get a mutable reference to a row

source

pub fn get_row(&self, row: usize) -> Option<&Row>

Get an immutable reference to a row

source

pub fn add_row(&mut self, row: Row) -> &mut Row

Append a row in the table, transferring ownership of this row to the table and returning a mutable reference to the row

source

pub fn add_empty_row(&mut self) -> &mut Row

Append an empty row in the table. Return a mutable reference to this new row.

source

pub fn insert_row(&mut self, index: usize, row: Row) -> &mut Row

Insert row at the position index, and return a mutable reference to this row. If index is higher than current numbers of rows, row is appended at the end of the table

source

pub fn set_element( &mut self, element: &str, column: usize, row: usize ) -> Result<(), &str>

Modify a single element in the table

source

pub fn remove_row(&mut self, index: usize)

Remove the row at position index. Silently skip if the row does not exist

source

pub fn column_iter(&self, column: usize) -> ColumnIter<'_>

Return an iterator over the immutable cells of the column specified by column

source

pub fn column_iter_mut(&mut self, column: usize) -> ColumnIterMut<'_>

Return an iterator over the mutable cells of the column specified by column

source

pub fn row_iter(&self) -> Iter<'_, Row>

Returns an iterator over immutable rows

source

pub fn row_iter_mut(&mut self) -> IterMut<'_, Row>

Returns an iterator over mutable rows

source

pub fn print<T: Write + ?Sized>(&self, out: &mut T) -> Result<usize, Error>

Print the table to out and returns the number of lines printed, or an error

source

pub fn print_term<T: Terminal + ?Sized>( &self, out: &mut T ) -> Result<usize, Error>

Print the table to terminal out, applying styles when needed and returns the number of lines printed, or an error

source

pub fn print_tty(&self, force_colorize: bool) -> usize

Print the table to standard output. Colors won’t be displayed unless stdout is a tty terminal, or force_colorize is set to true. In ANSI terminals, colors are displayed using ANSI escape characters. When for example the output is redirected to a file, or piped to another program, the output is considered as not beeing tty, and ANSI escape characters won’t be displayed unless force colorize is set to true.

§Returns

The number of lines printed

§Panic

Panic if writing to standard output fails

source

pub fn printstd(&self) -> usize

Print the table to standard output. Colors won’t be displayed unless stdout is a tty terminal. This means that if stdout is redirected to a file, or piped to another program, no color will be displayed. To force colors rendering, use print_tty() method. Calling printstd() is equivalent to calling print_tty(false)

§Returns

The number of lines printed

§Panic

Panic if writing to standard output fails

Trait Implementations§

source§

impl Clone for Table

source§

fn clone(&self) -> Table

Returns a copy 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 Debug for Table

source§

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

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

impl Display for Table

source§

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

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

impl<A: Into<Row>> Extend<A> for Table

source§

fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<T, A, B> From<T> for Table
where B: ToString, A: IntoIterator<Item = B>, T: IntoIterator<Item = A>,

source§

fn from(it: T) -> Table

Converts to this type from the input type.
source§

impl<B: ToString, A: IntoIterator<Item = B>> FromIterator<A> for Table

source§

fn from_iter<T>(iterator: T) -> Table
where T: IntoIterator<Item = A>,

Creates a value from an iterator. Read more
source§

impl FromIterator<Row> for Table

source§

fn from_iter<T>(iterator: T) -> Table
where T: IntoIterator<Item = Row>,

Creates a value from an iterator. Read more
source§

impl Hash for Table

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 Index<usize> for Table

§

type Output = Row

The returned type after indexing.
source§

fn index(&self, idx: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl IndexMut<usize> for Table

source§

fn index_mut(&mut self, idx: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<'a> IntoIterator for &'a Table

§

type Item = &'a Row

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, Row>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a> IntoIterator for &'a mut Table

§

type Item = &'a mut Row

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a, Row>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl PartialEq for Table

source§

fn eq(&self, other: &Table) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Table

source§

impl StructuralPartialEq for Table

Auto Trait Implementations§

§

impl Freeze for Table

§

impl RefUnwindSafe for Table

§

impl Send for Table

§

impl Sync for Table

§

impl Unpin for Table

§

impl UnwindSafe for Table

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> 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<'a, T, E> Slice<'a, E> for T
where T: AsTableSlice, [Row]: Index<E, Output = [Row]>,

§

type Output = TableSlice<'a>

Type output after slicing
source§

fn slice(&'a self, arg: E) -> <T as Slice<'a, E>>::Output

Get a slice from self
source§

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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

§

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.