pub struct Style<T, B, L, R, H, V, HLines = [HorizontalLine; N], VLines = [VerticalLine; N]> { /* private fields */ }
Expand description
Style is represents a theme of a Table
.
It tries to limit an controlling a valid state of it.
It doesn’t allow to call method Style::top_left_corner
unless Style::left
and Style::top
is set.
You can turn Style
into RawStyle
to have more controll using Into
implementation.
§Example
use tabled::{Table, Style};
let style = Style::ascii()
.bottom('*')
.inner_intersection(' ');
let data = vec!["Hello", "2021"];
let table = Table::new(&data).with(style).to_string();
println!("{}", table);
Implementations§
Source§impl Style<(), (), (), (), (), (), (), ()>
impl Style<(), (), (), (), (), (), (), ()>
Sourcepub const fn empty() -> Style<(), (), (), (), (), ()>
pub const fn empty() -> Style<(), (), (), (), (), ()>
This style is a style with no styling options on,
id destribution link
0 Fedora https://getfedora.org/
2 OpenSUSE https://www.opensuse.org/
3 Endeavouros https://endeavouros.com/
Note: The cells in the example have 1-left and 1-right indent.
This style can be used as a base style to build a custom one.
let style = Style::empty()
.top('*')
.bottom('*')
.vertical('#')
.bottom_intersection('^')
.top_intersection('*');
Sourcepub const fn blank() -> Style<(), (), (), (), (), On>
pub const fn blank() -> Style<(), (), (), (), (), On>
This style is analog of empty
but with a vertical space(’ ’) line.
id destribution link
0 Fedora https://getfedora.org/
2 OpenSUSE https://www.opensuse.org/
3 Endeavouros https://endeavouros.com/
Sourcepub const fn ascii() -> Style<On, On, On, On, On, On>
pub const fn ascii() -> Style<On, On, On, On, On, On>
This is a style which relays only on ASCII charset.
It has horizontal and vertical lines.
+----+--------------+---------------------------+
| id | destribution | link |
+----+--------------+---------------------------+
| 0 | Fedora | https://getfedora.org/ |
+----+--------------+---------------------------+
| 2 | OpenSUSE | https://www.opensuse.org/ |
+----+--------------+---------------------------+
| 3 | Endeavouros | https://endeavouros.com/ |
+----+--------------+---------------------------+
Sourcepub const fn psql() -> Style<(), (), (), (), (), On, [HorizontalLine; N]>
pub const fn psql() -> Style<(), (), (), (), (), On, [HorizontalLine; N]>
psql
style looks like a table style PostgreSQL
uses.
It has only 1 horizontal line which splits header. And no left and right vertical lines.
id | destribution | link
----+--------------+---------------------------
0 | Fedora | https://getfedora.org/
2 | OpenSUSE | https://www.opensuse.org/
3 | Endeavouros | https://endeavouros.com/
Sourcepub const fn markdown() -> Style<(), (), On, On, (), On, [HorizontalLine; N]>
pub const fn markdown() -> Style<(), (), On, On, (), On, [HorizontalLine; N]>
markdown
style mimics a Markdown
table style.
| id | destribution | link |
|----|--------------|---------------------------|
| 0 | Fedora | https://getfedora.org/ |
| 2 | OpenSUSE | https://www.opensuse.org/ |
| 3 | Endeavouros | https://endeavouros.com/ |
Sourcepub const fn modern() -> Style<On, On, On, On, On, On>
pub const fn modern() -> Style<On, On, On, On, On, On>
This style is analog of Style::ascii
which uses UTF-8 charset.
It has vertical and horizontal split lines.
┌────┬──────────────┬───────────────────────────┐
│ id │ destribution │ link │
├────┼──────────────┼───────────────────────────┤
│ 0 │ Fedora │ https://getfedora.org/ │
├────┼──────────────┼───────────────────────────┤
│ 2 │ OpenSUSE │ https://www.opensuse.org/ │
├────┼──────────────┼───────────────────────────┤
│ 3 │ Endeavouros │ https://endeavouros.com/ │
└────┴──────────────┴───────────────────────────┘
Sourcepub const fn sharp() -> Style<On, On, On, On, (), On, [HorizontalLine; N]>
pub const fn sharp() -> Style<On, On, On, On, (), On, [HorizontalLine; N]>
This style looks like a Style::modern
but without horozizontal lines except a header.
Beware: It uses UTF-8 characters.
┌────┬──────────────┬───────────────────────────┐
│ id │ destribution │ link │
├────┼──────────────┼───────────────────────────┤
│ 0 │ Fedora │ https://getfedora.org/ │
│ 2 │ OpenSUSE │ https://www.opensuse.org/ │
│ 3 │ Endeavouros │ https://endeavouros.com/ │
└────┴──────────────┴───────────────────────────┘
Sourcepub const fn rounded() -> Style<On, On, On, On, (), On, [HorizontalLine; N]>
pub const fn rounded() -> Style<On, On, On, On, (), On, [HorizontalLine; N]>
This style looks like a Style::sharp
but with rounded corners.
Beware: It uses UTF-8 characters.
╭────┬──────────────┬───────────────────────────╮
│ id │ destribution │ link │
├────┼──────────────┼───────────────────────────┤
│ 0 │ Fedora │ https://getfedora.org/ │
│ 2 │ OpenSUSE │ https://www.opensuse.org/ │
│ 3 │ Endeavouros │ https://endeavouros.com/ │
╰────┴──────────────┴───────────────────────────╯
Sourcepub const fn extended() -> Style<On, On, On, On, On, On>
pub const fn extended() -> Style<On, On, On, On, On, On>
This style uses a chars which resembles ‘2 lines’.
Beware: It uses UTF8 characters.
╔════╦══════════════╦═══════════════════════════╗
║ id ║ destribution ║ link ║
╠════╬══════════════╬═══════════════════════════╣
║ 0 ║ Fedora ║ https://getfedora.org/ ║
╠════╬══════════════╬═══════════════════════════╣
║ 2 ║ OpenSUSE ║ https://www.opensuse.org/ ║
╠════╬══════════════╬═══════════════════════════╣
║ 3 ║ Endeavouros ║ https://endeavouros.com/ ║
╚════╩══════════════╩═══════════════════════════╝
Sourcepub const fn dots() -> Style<On, On, On, On, On, On>
pub const fn dots() -> Style<On, On, On, On, On, On>
This is a style uses only ‘.’ and ‘:’ chars. It has a vertical and horizontal split lines.
.................................................
: id : destribution : link :
:....:..............:...........................:
: 0 : Fedora : https://getfedora.org/ :
:....:..............:...........................:
: 2 : OpenSUSE : https://www.opensuse.org/ :
:....:..............:...........................:
: 3 : Endeavouros : https://endeavouros.com/ :
:....:..............:...........................:
Sourcepub const fn re_structured_text() -> Style<On, On, (), (), (), On, [HorizontalLine; N]>
pub const fn re_structured_text() -> Style<On, On, (), (), (), On, [HorizontalLine; N]>
This style is one of table views in ReStructuredText
.
==== ============== ===========================
id destribution link
==== ============== ===========================
0 Fedora https://getfedora.org/
2 OpenSUSE https://www.opensuse.org/
3 Endeavouros https://endeavouros.com/
==== ============== ===========================
Sourcepub const fn ascii_rounded() -> Style<On, On, On, On, (), On>
pub const fn ascii_rounded() -> Style<On, On, On, On, (), On>
This is a theme analog of Style::rounded
, but in using ascii charset and
with no horizontal lines.
.-----------------------------------------------.
| id | destribution | link |
| 0 | Fedora | https://getfedora.org/ |
| 2 | OpenSUSE | https://www.opensuse.org/ |
| 3 | Endeavouros | https://endeavouros.com/ |
'-----------------------------------------------'
Sourcepub const fn correct_spans() -> StyleCorrectSpan
pub const fn correct_spans() -> StyleCorrectSpan
Try to fix the style when table contains spans.
By default Style
doesn’t implies any logic to better render split lines when
Span
is used.
So this function can be used to set the split lines in regard of spans used.
§Example
use tabled::{TableIteratorExt, Style, Modify, format::Format, Span, object::Cell};
let data = vec![
("09", "June", "2022"),
("10", "July", "2022"),
];
let mut table = data.table();
table
.with(
Modify::new(Cell(0, 0))
.with(Format::new(|_| String::from("date")))
.with(Span::column(3))
);
assert_eq!(
table.to_string(),
concat!(
"+----+------+------+\n",
"| date |\n",
"+----+------+------+\n",
"| 09 | June | 2022 |\n",
"+----+------+------+\n",
"| 10 | July | 2022 |\n",
"+----+------+------+",
)
);
table.with(Style::correct_spans());
assert_eq!(
table.to_string(),
concat!(
"+------------------+\n",
"| date |\n",
"+----+------+------+\n",
"| 09 | June | 2022 |\n",
"+----+------+------+\n",
"| 10 | July | 2022 |\n",
"+----+------+------+",
)
);
Source§impl<T, B, L, R, H, V, HLines, VLines> Style<T, B, L, R, H, V, HLines, VLines>
impl<T, B, L, R, H, V, HLines, VLines> Style<T, B, L, R, H, V, HLines, VLines>
Sourcepub const fn get_frame(&self) -> Border
pub const fn get_frame(&self) -> Border
Frame function returns a frame as a border.
§Example
use tabled::{Table, Style, Highlight, object::Rows};
let data = [["10:52:19", "Hello"], ["10:52:20", "World"]];
let mut table = Table::new(data);
table.with(Highlight::new(Rows::first(), Style::modern().get_frame()));
assert_eq!(
table.to_string(),
concat!(
"┌──────────────────┐\n",
"│ 0 | 1 │\n",
"└──────────────────┘\n",
"| 10:52:19 | Hello |\n",
"+----------+-------+\n",
"| 10:52:20 | World |\n",
"+----------+-------+",
)
);
Sourcepub const fn get_horizontal(&self) -> Line
pub const fn get_horizontal(&self) -> Line
Get a Style
’s default horizontal line.
It doesn’t return an overloaded line via Style::horizontals
.
§Example
use tabled::{style::{Style, HorizontalLine, Line}, TableIteratorExt};
let table = (0..3)
.map(|i| ("Hello", "World", i))
.table()
.with(Style::ascii().off_horizontal().horizontals([HorizontalLine::new(1, Style::modern().get_horizontal())]))
.to_string();
assert_eq!(
table,
concat!(
"+-------+-------+-----+\n",
"| &str | &str | i32 |\n",
"├───────┼───────┼─────┤\n",
"| Hello | World | 0 |\n",
"| Hello | World | 1 |\n",
"| Hello | World | 2 |\n",
"+-------+-------+-----+",
)
)
Sourcepub const fn get_vertical(&self) -> Line
pub const fn get_vertical(&self) -> Line
Get a Style
’s default horizontal line.
It doesn’t return an overloaded line via Style::verticals
.
§Example
use tabled::{style::{Style, VerticalLine, Line}, TableIteratorExt};
let table = (0..3)
.map(|i| ("Hello", "World", i))
.table()
.with(Style::ascii().off_horizontal().verticals([VerticalLine::new(1, Style::modern().get_vertical())]))
.to_string();
assert_eq!(
table,
concat!(
"+-------┬-------+-----+\n",
"| &str │ &str | i32 |\n",
"| Hello │ World | 0 |\n",
"| Hello │ World | 1 |\n",
"| Hello │ World | 2 |\n",
"+-------┴-------+-----+",
)
)
Sourcepub fn top(self, c: char) -> Style<On, B, L, R, H, V, HLines, VLines>
pub fn top(self, c: char) -> Style<On, B, L, R, H, V, HLines, VLines>
Sets a top border.
Any corners and intersections which were set will be overridden.
Sourcepub fn bottom(self, c: char) -> Style<T, On, L, R, H, V, HLines, VLines>
pub fn bottom(self, c: char) -> Style<T, On, L, R, H, V, HLines, VLines>
Sets a bottom border.
Any corners and intersections which were set will be overridden.
Sourcepub fn left(self, c: char) -> Style<T, B, On, R, H, V, HLines, VLines>
pub fn left(self, c: char) -> Style<T, B, On, R, H, V, HLines, VLines>
Sets a left border.
Any corners and intersections which were set will be overridden.
Sourcepub fn right(self, c: char) -> Style<T, B, L, On, H, V, HLines, VLines>
pub fn right(self, c: char) -> Style<T, B, L, On, H, V, HLines, VLines>
Sets a right border.
Any corners and intersections which were set will be overridden.
Sourcepub fn horizontal(self, c: char) -> Style<T, B, L, R, On, V, HLines, VLines>
pub fn horizontal(self, c: char) -> Style<T, B, L, R, On, V, HLines, VLines>
Sets a horizontal split line.
Any corners and intersections which were set will be overridden.
Sourcepub fn vertical(self, c: char) -> Style<T, B, L, R, H, On, HLines, VLines>
pub fn vertical(self, c: char) -> Style<T, B, L, R, H, On, HLines, VLines>
Sets a vertical split line.
Any corners and intersections which were set will be overridden.
Sourcepub fn horizontals<NewLines>(
self,
lines: NewLines,
) -> Style<T, B, L, R, H, V, NewLines, VLines>
pub fn horizontals<NewLines>( self, lines: NewLines, ) -> Style<T, B, L, R, H, V, NewLines, VLines>
Set border horizontal lines.
§Example
use tabled::{style::{Style, HorizontalLine, Line}, TableIteratorExt};
let table = (0..3)
.map(|i| ("Hello", i))
.table()
.with(Style::rounded().horizontals((1..4).map(|i| HorizontalLine::new(i, Line::filled('#')))))
.to_string();
assert_eq!(
table,
concat!(
"╭───────┬─────╮\n",
"│ &str │ i32 │\n",
"###############\n",
"│ Hello │ 0 │\n",
"###############\n",
"│ Hello │ 1 │\n",
"###############\n",
"│ Hello │ 2 │\n",
"╰───────┴─────╯",
)
)
Sourcepub fn verticals<NewLines>(
self,
lines: NewLines,
) -> Style<T, B, L, R, H, V, HLines, NewLines>
pub fn verticals<NewLines>( self, lines: NewLines, ) -> Style<T, B, L, R, H, V, HLines, NewLines>
Set border vertical lines.
§Example
use tabled::{style::{Style, VerticalLine, Line}, TableIteratorExt};
let table = (0..3)
.map(|i| ("Hello", i))
.table()
.with(Style::rounded().verticals((0..3).map(|i| VerticalLine::new(i, Line::filled('#')))))
.to_string();
assert_eq!(
table,
concat!(
"#───────#─────#\n",
"# &str # i32 #\n",
"├───────┼─────┤\n",
"# Hello # 0 #\n",
"# Hello # 1 #\n",
"# Hello # 2 #\n",
"#───────#─────#",
)
)
Sourcepub fn off_horizontals(
self,
) -> Style<T, B, L, R, H, V, [HorizontalLine; N], VLines>
pub fn off_horizontals( self, ) -> Style<T, B, L, R, H, V, [HorizontalLine; N], VLines>
Removes all horizontal lines set by Style::horizontals
Sourcepub fn off_verticals(self) -> Style<T, B, L, R, H, V, HLines, [VerticalLine; N]>
pub fn off_verticals(self) -> Style<T, B, L, R, H, V, HLines, [VerticalLine; N]>
Removes all verticals lines set by Style::verticals
Source§impl<B, R, H, V, HLines, VLines> Style<On, B, On, R, H, V, HLines, VLines>
impl<B, R, H, V, HLines, VLines> Style<On, B, On, R, H, V, HLines, VLines>
Sourcepub fn top_left_corner(self, c: char) -> Self
pub fn top_left_corner(self, c: char) -> Self
Sets a top left corner.
Source§impl<B, L, H, V, HLines, VLines> Style<On, B, L, On, H, V, HLines, VLines>
impl<B, L, H, V, HLines, VLines> Style<On, B, L, On, H, V, HLines, VLines>
Sourcepub fn top_right_corner(self, c: char) -> Self
pub fn top_right_corner(self, c: char) -> Self
Sets a top right corner.
Source§impl<T, L, H, V, HLines, VLines> Style<T, On, L, On, H, V, HLines, VLines>
impl<T, L, H, V, HLines, VLines> Style<T, On, L, On, H, V, HLines, VLines>
Sourcepub fn bottom_right_corner(self, c: char) -> Self
pub fn bottom_right_corner(self, c: char) -> Self
Sets a bottom right corner.
Source§impl<T, R, H, V, HLines, VLines> Style<T, On, On, R, H, V, HLines, VLines>
impl<T, R, H, V, HLines, VLines> Style<T, On, On, R, H, V, HLines, VLines>
Sourcepub fn bottom_left_corner(self, c: char) -> Self
pub fn bottom_left_corner(self, c: char) -> Self
Sets a bottom left corner.
Source§impl<T, B, R, V, HLines, VLines> Style<T, B, On, R, On, V, HLines, VLines>
impl<T, B, R, V, HLines, VLines> Style<T, B, On, R, On, V, HLines, VLines>
Sourcepub fn left_intersection(self, c: char) -> Self
pub fn left_intersection(self, c: char) -> Self
Sets a left intersection char.
Source§impl<T, B, L, V, HLines, VLines> Style<T, B, L, On, On, V, HLines, VLines>
impl<T, B, L, V, HLines, VLines> Style<T, B, L, On, On, V, HLines, VLines>
Sourcepub fn right_intersection(self, c: char) -> Self
pub fn right_intersection(self, c: char) -> Self
Sets a right intersection char.
Source§impl<B, L, R, H, HLines, VLines> Style<On, B, L, R, H, On, HLines, VLines>
impl<B, L, R, H, HLines, VLines> Style<On, B, L, R, H, On, HLines, VLines>
Sourcepub fn top_intersection(self, c: char) -> Self
pub fn top_intersection(self, c: char) -> Self
Sets a top intersection char.
Source§impl<T, L, R, H, HLines, VLines> Style<T, On, L, R, H, On, HLines, VLines>
impl<T, L, R, H, HLines, VLines> Style<T, On, L, R, H, On, HLines, VLines>
Sourcepub fn bottom_intersection(self, c: char) -> Self
pub fn bottom_intersection(self, c: char) -> Self
Sets a bottom intersection char.
Source§impl<T, B, L, R, HLines, VLines> Style<T, B, L, R, On, On, HLines, VLines>
impl<T, B, L, R, HLines, VLines> Style<T, B, L, R, On, On, HLines, VLines>
Sourcepub fn inner_intersection(self, c: char) -> Self
pub fn inner_intersection(self, c: char) -> Self
Sets an inner intersection char. A char between horizontal and vertical split lines.
Source§impl<B, L, R, H, V, HLines, VLines> Style<On, B, L, R, H, V, HLines, VLines>
impl<B, L, R, H, V, HLines, VLines> Style<On, B, L, R, H, V, HLines, VLines>
Source§impl<T, L, R, H, V, HLines, VLines> Style<T, On, L, R, H, V, HLines, VLines>
impl<T, L, R, H, V, HLines, VLines> Style<T, On, L, R, H, V, HLines, VLines>
Sourcepub fn off_bottom(
self,
) -> Style<T, (), L, R, H, V, HLines, VerticalLineIter<VLines::IntoIter>>
pub fn off_bottom( self, ) -> Style<T, (), L, R, H, V, HLines, VerticalLineIter<VLines::IntoIter>>
Removes bottom border.
Source§impl<T, B, R, H, V, HLines, VLines> Style<T, B, On, R, H, V, HLines, VLines>
impl<T, B, R, H, V, HLines, VLines> Style<T, B, On, R, H, V, HLines, VLines>
Source§impl<T, B, L, H, V, HLines, VLines> Style<T, B, L, On, H, V, HLines, VLines>
impl<T, B, L, H, V, HLines, VLines> Style<T, B, L, On, H, V, HLines, VLines>
Source§impl<T, B, L, R, V, HLines, VLines> Style<T, B, L, R, On, V, HLines, VLines>
impl<T, B, L, R, V, HLines, VLines> Style<T, B, L, R, On, V, HLines, VLines>
Sourcepub fn off_horizontal(
self,
) -> Style<T, B, L, R, (), V, HLines, VerticalLineIter<VLines::IntoIter>>
pub fn off_horizontal( self, ) -> Style<T, B, L, R, (), V, HLines, VerticalLineIter<VLines::IntoIter>>
Removes horizontal split lines.
Not including custom split lines.