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 TableSlice<'_>
impl TableSlice<'_>
Sourcepub fn column_iter(&self, column: usize) -> ColumnIter<'_> ⓘ
pub fn column_iter(&self, column: usize) -> ColumnIter<'_> ⓘ
Returns an iterator over the immutable cells of the column specified by column
Sourcepub fn print<T: Write + ?Sized>(&self, out: &mut T) -> Result<usize, Error>
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
Sourcepub fn print_term<T: Terminal + ?Sized>(
&self,
out: &mut T,
) -> Result<usize, Error>
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
Sourcepub fn print_tty(&self, force_colorize: bool) -> Result<usize, Error>
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
Sourcepub fn printstd(&self)
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?
7fn main() {
8 let mut table = table![[0, 0, 0], [1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4], [5, 5, 5]];
9 table.set_titles(row!["t1", "t2", "t3"]);
10
11 let slice = table.slice(..);
12 let slice = slice.slice(2..);
13 let slice = slice.slice(..3);
14
15 /*
16 Will print
17 +----+----+----+
18 | t1 | t2 | t3 |
19 +====+====+====+
20 | 2 | 2 | 2 |
21 +----+----+----+
22 | 3 | 3 | 3 |
23 +----+----+----+
24 | 4 | 4 | 4 |
25 +----+----+----+
26 */
27 slice.printstd();
28
29 // This is equivalent to
30 let slice = table.slice(2..5);
31 slice.printstd();
32}Trait Implementations§
Source§impl<'a> AsRef<TableSlice<'a>> for TableSlice<'a>
impl<'a> AsRef<TableSlice<'a>> for TableSlice<'a>
Source§fn as_ref(&self) -> &TableSlice<'a>
fn as_ref(&self) -> &TableSlice<'a>
Source§impl AsTableSlice for TableSlice<'_>
impl AsTableSlice for TableSlice<'_>
Source§fn as_slice(&self) -> TableSlice<'_>
fn as_slice(&self) -> TableSlice<'_>
Source§impl<'a> Clone for TableSlice<'a>
impl<'a> Clone for TableSlice<'a>
Source§fn clone(&self) -> TableSlice<'a>
fn clone(&self) -> TableSlice<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more