pub struct IndexBuilder<'a> { /* private fields */ }
Expand description
IndexBuilder
helps to add an index to the table.
Index is a column on the left of the table.
It also can be used to transpose the table.
§Example
use tabled::builder::Builder;
let table = Builder::default()
.index()
.build();
Implementations§
Source§impl<'a> IndexBuilder<'a>
impl<'a> IndexBuilder<'a>
Sourcepub fn hide_index(&mut self) -> &mut Self
pub fn hide_index(&mut self) -> &mut Self
No flag makes builder to not use an index.
It may be useful when only Self::transpose
need to be used.
use tabled::builder::Builder;
let mut builder = Builder::default();
builder.set_columns(["i", "col-1", "col-2"]);
builder.add_record(["0", "value-1", "value-2"]);
builder.add_record(["2", "value-3", "value-4"]);
let mut builder = builder.index();
builder.hide_index();
let table = builder.build();
assert_eq!(
table.to_string(),
"+---+---------+---------+\n\
| i | col-1 | col-2 |\n\
+---+---------+---------+\n\
| 0 | value-1 | value-2 |\n\
+---+---------+---------+\n\
| 2 | value-3 | value-4 |\n\
+---+---------+---------+"
)
Sourcepub fn set_name(&mut self, name: Option<String>) -> &mut Self
pub fn set_name(&mut self, name: Option<String>) -> &mut Self
Set an index name.
When None
the name won’t be used.
Sourcepub fn set_index(&mut self, column: usize) -> &mut Self
pub fn set_index(&mut self, column: usize) -> &mut Self
Sets a index to the chosen column.
Also sets a name of the index to the column name.
§Example
use tabled::builder::Builder;
let mut builder = Builder::default();
builder.set_columns(["i", "column1", "column2"]);
builder.add_record(["0", "value1", "value2"]);
let mut builder = builder.index();
builder.set_index(1);
let table = builder.build();
assert_eq!(
table.to_string(),
"+---------+---+---------+\n\
| | i | column2 |\n\
+---------+---+---------+\n\
| column1 | | |\n\
+---------+---+---------+\n\
| value1 | 0 | value2 |\n\
+---------+---+---------+"
)
Sourcepub fn transpose(&mut self) -> &mut Self
pub fn transpose(&mut self) -> &mut Self
Transpose index and columns.
§Example
use tabled::builder::Builder;
let mut builder = Builder::default();
builder.set_columns(["i", "column-1", "column-2", "column-3"]);
builder.add_record(["0", "value-1", "value-2", "value-3"]);
builder.add_record(["1", "value-4", "value-5", "value-6"]);
builder.add_record(["2", "value-7", "value-8", "value-9"]);
let mut builder = builder.index();
builder.set_index(1).transpose();
let table = builder.build();
assert_eq!(
table.to_string(),
"+----------+---------+---------+---------+\n\
| column-1 | value-1 | value-4 | value-7 |\n\
+----------+---------+---------+---------+\n\
| i | 0 | 1 | 2 |\n\
+----------+---------+---------+---------+\n\
| column-2 | value-2 | value-5 | value-8 |\n\
+----------+---------+---------+---------+\n\
| column-3 | value-3 | value-6 | value-9 |\n\
+----------+---------+---------+---------+"
)
Sourcepub fn build(self) -> Table<VecRecords<CellInfo<'a>>>
pub fn build(self) -> Table<VecRecords<CellInfo<'a>>>
Builds a table.
Trait Implementations§
Source§impl<'a> Clone for IndexBuilder<'a>
impl<'a> Clone for IndexBuilder<'a>
Source§fn clone(&self) -> IndexBuilder<'a>
fn clone(&self) -> IndexBuilder<'a>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<'a> Debug for IndexBuilder<'a>
impl<'a> Debug for IndexBuilder<'a>
Source§impl<'a> From<IndexBuilder<'a>> for Builder<'a>
impl<'a> From<IndexBuilder<'a>> for Builder<'a>
Source§fn from(index_builder: IndexBuilder<'a>) -> Self
fn from(index_builder: IndexBuilder<'a>) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl<'a> Freeze for IndexBuilder<'a>
impl<'a> RefUnwindSafe for IndexBuilder<'a>
impl<'a> Send for IndexBuilder<'a>
impl<'a> Sync for IndexBuilder<'a>
impl<'a> Unpin for IndexBuilder<'a>
impl<'a> UnwindSafe for IndexBuilder<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more