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
impl ColumnNames
Sourcepub fn head() -> Self
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 |"
"+-------+-------+"
);
Sourcepub fn new<I>(names: I) -> Self
pub fn new<I>(names: I) -> Self
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 |"
"+-------+-------+"
);
Sourcepub fn color<T>(self, color: T) -> Self
pub fn color<T>(self, color: T) -> Self
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 |"
"+-------+-------+"
);
Sourcepub fn line(self, i: usize) -> Self
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--+"
);
Sourcepub fn alignment<T>(self, alignment: T) -> Self
pub fn alignment<T>(self, alignment: T) -> Self
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
impl Clone for ColumnNames
Source§fn clone(&self) -> ColumnNames
fn clone(&self) -> ColumnNames
Returns a duplicate 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 Debug for ColumnNames
impl Debug for ColumnNames
Source§impl TableOption<VecRecords<Text<String>>, ColoredConfig, CompleteDimension> for ColumnNames
impl TableOption<VecRecords<Text<String>>, ColoredConfig, CompleteDimension> for ColumnNames
Source§fn change(
self,
records: &mut VecRecords<Text<String>>,
cfg: &mut ColoredConfig,
dims: &mut CompleteDimension,
)
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>
fn hint_change(&self) -> Option<Entity>
A hint whether an
TableOption
is going to change table layout. Read moreAuto Trait Implementations§
impl Freeze for ColumnNames
impl RefUnwindSafe for ColumnNames
impl Send for ColumnNames
impl Sync for ColumnNames
impl Unpin for ColumnNames
impl UnwindSafe for ColumnNames
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