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§

Write the table to the specified writer.

Write the table to the specified writer.

This allows for format customisation.

Get the number of rows

Check if the table slice is empty

Get an immutable reference to a row

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

Returns an iterator over immutable rows

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

Print the table to terminal out, applying styles when needed and returns the number of line printed, or an 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

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();
}

Print table in HTML format to out.

Trait Implementations§

Converts this type into a shared reference of the (usually inferred) input type.
Get a slice from self
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Type output after slicing
Get a slice from self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.