tabled::builder

Struct IndexBuilder

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

Source

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\
     +---+---------+---------+"
)
Source

pub fn set_name(&mut self, name: Option<String>) -> &mut Self

Set an index name.

When None the name won’t be used.

Source

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\
     +---------+---+---------+"
)
Source

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\
     +----------+---------+---------+---------+"
)
Source

pub fn build(self) -> Table<VecRecords<CellInfo<'a>>>

Builds a table.

Trait Implementations§

Source§

impl<'a> Clone for IndexBuilder<'a>

Source§

fn clone(&self) -> IndexBuilder<'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 IndexBuilder<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<IndexBuilder<'a>> for Builder<'a>

Source§

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