Struct prettytable::TableSlice

source ·
pub struct TableSlice<'a> { /* private fields */ }
Expand description

A borrowed immutable Table slice A TableSlice is obtained by slicing a Table with the Slice::slice method.

§Examples

use prettytable::{Table, Slice};
let table = table![[1, 2, 3], [4, 5, 6], [7, 8, 9]];
let slice = table.slice(1..);
slice.printstd(); // Prints only rows 1 and 2

//Also supports other syntax :
table.slice(..);
table.slice(..2);
table.slice(1..3);

Implementations§

source§

impl<'a> TableSlice<'a>

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<'a> TableSlice<'a>

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 slice is empty

source

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

Get an immutable reference to a row

source

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

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

source

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

Returns an iterator over immutable 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 line 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 line 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<'a> AsRef<TableSlice<'a>> for TableSlice<'a>

source§

fn as_ref(&self) -> &TableSlice<'a>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'a> Clone for TableSlice<'a>

source§

fn clone(&self) -> TableSlice<'a>

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<'a> Debug for TableSlice<'a>

source§

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

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

impl<'a> Display for TableSlice<'a>

source§

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

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

impl<'a> Hash for TableSlice<'a>

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<'a> Index<usize> for TableSlice<'a>

§

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<'a> IntoIterator for &'a TableSlice<'a>

§

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> PartialEq for TableSlice<'a>

source§

fn eq(&self, other: &TableSlice<'a>) -> 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<'a> Copy for TableSlice<'a>

source§

impl<'a> Eq for TableSlice<'a>

source§

impl<'a> StructuralPartialEq for TableSlice<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for TableSlice<'a>

§

impl<'a> RefUnwindSafe for TableSlice<'a>

§

impl<'a> Send for TableSlice<'a>

§

impl<'a> Sync for TableSlice<'a>

§

impl<'a> Unpin for TableSlice<'a>

§

impl<'a> UnwindSafe for TableSlice<'a>

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.