prettytable

Struct 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 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) -> Result<usize, Error>

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

A Result holding the number of lines printed, or an io::Error if any failure happens

Source

pub fn printstd(&self)

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. Any failure to print is ignored. For better control, use print_tty(). Calling printstd() is equivalent to calling print_tty(false) and ignoring the result.

Examples found in repository?
examples/slices.rs (line 30)
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
fn main() {
    let mut table = table![
        [0, 0, 0],
        [1, 1, 1],
        [2, 2, 2],
        [3, 3, 3],
        [4, 4, 4],
        [5, 5, 5]
    ];
    table.set_titles(row!["t1", "t2", "t3"]);

    let slice = table.slice(..);
    let slice = slice.slice(2..);
    let slice = slice.slice(..3);

    /*
        Will print
        +----+----+----+
        | t1 | t2 | t3 |
        +====+====+====+
        | 2  | 2  | 2  |
        +----+----+----+
        | 3  | 3  | 3  |
        +----+----+----+
        | 4  | 4  | 4  |
        +----+----+----+
    */
    slice.printstd();

    // This is equivalent to
    let slice = table.slice(2..5);
    slice.printstd();
}
Source

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

Print table in HTML format to out.

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

Source§

fn as_slice(&self) -> TableSlice<'_>

Get a slice from self
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>

Source§

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>

Source§

type Item = &'a Row

The type of the elements being iterated over.
Source§

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

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<'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> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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]>,

Source§

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,

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

Source§

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

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.