pub struct Extract<R, C> { /* private fields */ }
Expand description
Returns a new Table
that reflects a segment of the referenced Table
§Example
use tabled::{Table, format::Format, object::Rows, Modify, Extract};
let data = vec![
(0, "Grodno", true),
(1, "Minsk", true),
(2, "Hamburg", false),
(3, "Brest", true),
];
let table = Table::new(&data)
.with(Modify::new(Rows::new(1..)).with(Format::new(|s| format!(": {} :", s))))
.with(Extract::segment(1..=2, 1..))
.to_string();
assert_eq!(table, "+------------+----------+\n\
| : Grodno : | : true : |\n\
+------------+----------+\n\
| : Minsk : | : true : |\n\
+------------+----------+");
Implementations§
Source§impl<R, C> Extract<R, C>
impl<R, C> Extract<R, C>
Sourcepub fn segment(rows: R, columns: C) -> Self
pub fn segment(rows: R, columns: C) -> Self
Returns a new Table
that reflects a segment of the referenced Table
let rows = 1..3;
let columns = 1..;
Extract::segment(rows, columns);
§Range
A RangeBounds
argument can be less than or equal to the shape of a Table
If a RangeBounds
argument is malformed or too large the thread will panic
// Empty Full Out of bounds
Extract::segment(0..0, 0..0) Extract::segment(.., ..) Extract::segment(0..1, ..4)
[]. . . [O O O [O O O X] //ERROR
. . . O O O . . .
. . . O O O] . . .
Source§impl<R> Extract<R, RangeFull>where
R: RangeBounds<usize>,
impl<R> Extract<R, RangeFull>where
R: RangeBounds<usize>,
Sourcepub fn rows(rows: R) -> Self
pub fn rows(rows: R) -> Self
Returns a new Table
that reflects a segment of the referenced Table
The segment is defined by RangeBounds
Extract::rows(1..3);
§Range
A RangeBounds
argument can be less than or equal to the shape of a Table
If a RangeBounds
argument is malformed or too large the thread will panic
// Empty Full Out of bounds
Extract::rows(0..0) Extract::rows(..) Extract::rows(0..4)
[]. . . [O O O [O O O
. . . O O O O O O
. . . O O O] O O O
X X X] // ERROR
Source§impl<C> Extract<RangeFull, C>where
C: RangeBounds<usize>,
impl<C> Extract<RangeFull, C>where
C: RangeBounds<usize>,
Sourcepub fn columns(columns: C) -> Self
pub fn columns(columns: C) -> Self
Returns a new Table
that reflects a segment of the referenced Table
The segment is defined by RangeBounds
Extract::columns(1..3);
§Range
A RangeBounds
argument can be less than or equal to the shape of a Table
If a RangeBounds
argument is malformed or too large the thread will panic
// Empty Full Out of bounds
Extract::columns(0..0) Extract::columns(..) Extract::columns(0..4)
[]. . . [O O O [O O O X
. . . O O O O O O X
. . . O O O] O O O X] // ERROR