tabled

Struct Style

Source
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<(), (), (), (), (), (), (), ()>

Source

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('*');
Source

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

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

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

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

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/  │
    └────┴──────────────┴───────────────────────────┘
Source

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/  │
    └────┴──────────────┴───────────────────────────┘
Source

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/  │
    ╰────┴──────────────┴───────────────────────────╯
Source

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/  ║
    ╚════╩══════════════╩═══════════════════════════╝
Source

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/  :
    :....:..............:...........................:
Source

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

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

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>

Source

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

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

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

pub fn top(self, c: char) -> Style<On, B, L, R, H, V, HLines, VLines>
where for<'a> &'a mut VLines: IntoIterator<Item = &'a mut VerticalLine>,

Sets a top border.

Any corners and intersections which were set will be overridden.

Source

pub fn bottom(self, c: char) -> Style<T, On, L, R, H, V, HLines, VLines>
where for<'a> &'a mut VLines: IntoIterator<Item = &'a mut VerticalLine>,

Sets a bottom border.

Any corners and intersections which were set will be overridden.

Source

pub fn left(self, c: char) -> Style<T, B, On, R, H, V, HLines, VLines>
where for<'a> &'a mut HLines: IntoIterator<Item = &'a mut HorizontalLine>,

Sets a left border.

Any corners and intersections which were set will be overridden.

Source

pub fn right(self, c: char) -> Style<T, B, L, On, H, V, HLines, VLines>
where for<'a> &'a mut HLines: IntoIterator<Item = &'a mut HorizontalLine>,

Sets a right border.

Any corners and intersections which were set will be overridden.

Source

pub fn horizontal(self, c: char) -> Style<T, B, L, R, On, V, HLines, VLines>
where for<'a> &'a mut VLines: IntoIterator<Item = &'a mut VerticalLine>,

Sets a horizontal split line.

Any corners and intersections which were set will be overridden.

Source

pub fn vertical(self, c: char) -> Style<T, B, L, R, H, On, HLines, VLines>
where for<'a> &'a mut HLines: IntoIterator<Item = &'a mut HorizontalLine>,

Sets a vertical split line.

Any corners and intersections which were set will be overridden.

Source

pub fn horizontals<NewLines>( self, lines: NewLines, ) -> Style<T, B, L, R, H, V, NewLines, VLines>
where NewLines: IntoIterator<Item = HorizontalLine> + Clone,

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",
        "╰───────┴─────╯",
    )
)
Source

pub fn verticals<NewLines>( self, lines: NewLines, ) -> Style<T, B, L, R, H, V, HLines, NewLines>
where NewLines: IntoIterator<Item = VerticalLine> + Clone,

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",
        "#───────#─────#",
    )
)
Source

pub fn off_horizontals( self, ) -> Style<T, B, L, R, H, V, [HorizontalLine; N], VLines>

Removes all horizontal lines set by Style::horizontals

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

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>

Source

pub fn off_top( self, ) -> Style<(), B, L, R, H, V, HLines, VerticalLineIter<VLines::IntoIter>>
where VLines: IntoIterator<Item = VerticalLine> + Clone,

Removes top border.

Source§

impl<T, L, R, H, V, HLines, VLines> Style<T, On, L, R, H, V, HLines, VLines>

Source

pub fn off_bottom( self, ) -> Style<T, (), L, R, H, V, HLines, VerticalLineIter<VLines::IntoIter>>
where VLines: IntoIterator<Item = VerticalLine> + Clone,

Removes bottom border.

Source§

impl<T, B, R, H, V, HLines, VLines> Style<T, B, On, R, H, V, HLines, VLines>

Source

pub fn off_left( self, ) -> Style<T, B, (), R, H, V, HorizontalLineIter<HLines::IntoIter>, VLines>
where HLines: IntoIterator<Item = HorizontalLine> + Clone,

Removes left border.

Source§

impl<T, B, L, H, V, HLines, VLines> Style<T, B, L, On, H, V, HLines, VLines>

Source

pub fn off_right( self, ) -> Style<T, B, L, (), H, V, HorizontalLineIter<HLines::IntoIter>, VLines>
where HLines: IntoIterator<Item = HorizontalLine> + Clone,

Removes right border.

Source§

impl<T, B, L, R, V, HLines, VLines> Style<T, B, L, R, On, V, HLines, VLines>

Source

pub fn off_horizontal( self, ) -> Style<T, B, L, R, (), V, HLines, VerticalLineIter<VLines::IntoIter>>
where VLines: IntoIterator<Item = VerticalLine> + Clone,

Removes horizontal split lines.

Not including custom split lines.

Source§

impl<T, B, L, R, H, HLines, VLines> Style<T, B, L, R, H, On, HLines, VLines>

Source

pub fn off_vertical( self, ) -> Style<T, B, L, R, H, (), HorizontalLineIter<HLines::IntoIter>, VLines>
where HLines: IntoIterator<Item = HorizontalLine> + Clone,

Removes vertical split lines.

Trait Implementations§

Source§

impl<T: Clone, B: Clone, L: Clone, R: Clone, H: Clone, V: Clone, HLines: Clone, VLines: Clone> Clone for Style<T, B, L, R, H, V, HLines, VLines>

Source§

fn clone(&self) -> Style<T, B, L, R, H, V, HLines, VLines>

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<T: Debug, B: Debug, L: Debug, R: Debug, H: Debug, V: Debug, HLines: Debug, VLines: Debug> Debug for Style<T, B, L, R, H, V, HLines, VLines>

Source§

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

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

impl<T, B, L, R, H, V, HLines, VLines> From<Style<T, B, L, R, H, V, HLines, VLines>> for RawStyle
where HLines: IntoIterator<Item = HorizontalLine>, VLines: IntoIterator<Item = VerticalLine>,

Source§

fn from(style: Style<T, B, L, R, H, V, HLines, VLines>) -> Self

Converts to this type from the input type.
Source§

impl<T, B, L, R, H, V, HLines, VLines, I> TableOption<I> for Style<T, B, L, R, H, V, HLines, VLines>
where I: Records, HLines: IntoIterator<Item = HorizontalLine> + Clone, VLines: IntoIterator<Item = VerticalLine> + Clone,

Source§

fn change(&mut self, table: &mut Table<I>)

The function modifies a Grid object.

Auto Trait Implementations§

§

impl<T, B, L, R, H, V, HLines, VLines> Freeze for Style<T, B, L, R, H, V, HLines, VLines>
where HLines: Freeze, VLines: Freeze,

§

impl<T, B, L, R, H, V, HLines, VLines> RefUnwindSafe for Style<T, B, L, R, H, V, HLines, VLines>

§

impl<T, B, L, R, H, V, HLines, VLines> Send for Style<T, B, L, R, H, V, HLines, VLines>
where HLines: Send, VLines: Send, T: Send, B: Send, L: Send, R: Send, H: Send, V: Send,

§

impl<T, B, L, R, H, V, HLines, VLines> Sync for Style<T, B, L, R, H, V, HLines, VLines>
where HLines: Sync, VLines: Sync, T: Sync, B: Sync, L: Sync, R: Sync, H: Sync, V: Sync,

§

impl<T, B, L, R, H, V, HLines, VLines> Unpin for Style<T, B, L, R, H, V, HLines, VLines>
where HLines: Unpin, VLines: Unpin, T: Unpin, B: Unpin, L: Unpin, R: Unpin, H: Unpin, V: Unpin,

§

impl<T, B, L, R, H, V, HLines, VLines> UnwindSafe for Style<T, B, L, R, H, V, HLines, VLines>
where HLines: UnwindSafe, VLines: UnwindSafe, T: UnwindSafe, B: UnwindSafe, L: UnwindSafe, R: UnwindSafe, H: UnwindSafe, V: UnwindSafe,

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.