Struct ColumnNames

Source
pub struct ColumnNames { /* private fields */ }
Expand description

ColumnNames sets strings on horizontal lines for the columns.

Notice that using a Default would reuse a names from the first row.

§Examples

use std::iter::FromIterator;
use tabled::{
    Table,
    settings::{themes::ColumnNames, Alignment},
};

let data = vec![
    vec!["Hello", "World"],
    vec!["Hello", "World"],
];

let mut table = Table::from_iter(data);
table.with(
    ColumnNames::new(["head1", "head2"])
        .line(2)
        .alignment(Alignment::right())
);

assert_eq!(
    table.to_string(),
    "+-------+-------+\n\
     | Hello | World |\n\
     +-------+-------+\n\
     | Hello | World |\n\
     +--head1+--head2+"
);

Default usage.

use std::iter::FromIterator;
use tabled::{Table, settings::themes::ColumnNames};

let data = vec![
    vec!["Hello", "World"],
    vec!["Hello", "World"],
];

let mut table = Table::from_iter(data);
table.with(ColumnNames::head());

assert_eq!(
    table.to_string(),
    "+Hello--+World--+\n\
     | Hello | World |\n\
     +-------+-------+"
);

Implementations§

Source§

impl ColumnNames

Source

pub fn head() -> Self

Creates a ColumnNames which will be removing the head row and putting it right on the given border.

§Example
use std::iter::FromIterator;
use tabled::{Table, settings::themes::ColumnNames, assert::assert_table};

let data = vec![
    vec!["head1", "head2"],
    vec!["Hello", "World"],
];

let mut table = Table::from_iter(data);
table.with(ColumnNames::head());

assert_table!(
    table,
    "+head1--+head2--+"
    "| Hello | World |"
    "+-------+-------+"
);
Source

pub fn new<I>(names: I) -> Self
where I: IntoIterator, I::Item: Into<String>,

Creates a ColumnNames with a given names.

Using a Default would reuse a names from the first row.

§Example
use std::iter::FromIterator;
use tabled::{Table, settings::themes::ColumnNames, assert::assert_table};

let data = vec![vec!["Hello", "World"]];
let mut table = Table::from_iter(data);
table.with(ColumnNames::new(["head1", "head2"]));

assert_table!(
    table,
    "+head1--+head2--+"
    "| Hello | World |"
    "+-------+-------+"
);
Source

pub fn color<T>(self, color: T) -> Self
where T: Into<ListValue<Color>>,

Set color for the column names.

By default there’s no colors.

§Example
use std::iter::FromIterator;
use tabled::Table;
use tabled::settings::{Color, themes::ColumnNames};
use tabled::assert::assert_table;

let data = vec![vec!["Hello", "World"]];
let mut table = Table::from_iter(data);
table.with(ColumnNames::new(["head1", "head2"]).color(vec![Color::FG_RED]));

assert_table!(
    table,
    "+\u{1b}[31mh\u{1b}[39m\u{1b}[31me\u{1b}[39m\u{1b}[31ma\u{1b}[39m\u{1b}[31md\u{1b}[39m\u{1b}[31m1\u{1b}[39m--+head2--+"
    "| Hello | World |"
    "+-------+-------+"
);
Source

pub fn line(self, i: usize) -> Self

Set a horizontal line the names will be applied to.

The default value is 0 (the top horizontal line).

§Example
use std::iter::FromIterator;
use tabled::{Table, settings::themes::ColumnNames};

let mut table = Table::from_iter(vec![vec!["Hello", "World"]]);
table.with(ColumnNames::new(["head1", "head2"]).line(1));

assert_eq!(
    table.to_string(),
    "+-------+-------+\n\
     | Hello | World |\n\
     +head1--+head2--+"
);
Source

pub fn alignment<T>(self, alignment: T) -> Self
where T: Into<ListValue<Alignment>>,

Set an alignment for the names.

By default it’s left aligned.

§Example
use std::iter::FromIterator;
use tabled::{
    Table,
    settings::{themes::ColumnNames, Alignment},
};

let mut table = Table::from_iter(vec![vec!["Hello", "World"]]);
table.with(ColumnNames::new(["head1", "head2"]).alignment(Alignment::right()));

assert_eq!(
    table.to_string(),
    "+--head1+--head2+\n\
     | Hello | World |\n\
     +-------+-------+"
);

Trait Implementations§

Source§

impl Clone for ColumnNames

Source§

fn clone(&self) -> ColumnNames

Returns a duplicate 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 Debug for ColumnNames

Source§

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

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

impl TableOption<VecRecords<Text<String>>, ColoredConfig, CompleteDimension> for ColumnNames

Source§

fn change( self, records: &mut VecRecords<Text<String>>, cfg: &mut ColoredConfig, dims: &mut CompleteDimension, )

The function modificaties of records and a grid configuration.
Source§

fn hint_change(&self) -> Option<Entity>

A hint whether an TableOption is going to change table layout. Read more

Auto Trait Implementations§

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.