Struct Span

Source
pub struct Span;
Expand description

Span represent a horizontal/column span setting for any cell on a Table.

use tabled::{settings::{Span, Modify}, Table};
use tabled::assert::assert_table;

let data = [[1, 2, 3], [4, 5, 6]];

let mut table = Table::new(data);
table.modify((0, 0), Span::row(2));
table.modify((0, 1), Span::column(2));
table.modify((2, 0), Span::column(1000));

assert_table!(
    table,
    "+---+---+---+"
    "| 0 | 1     |"
    "+   +---+---+"
    "|   | 2 | 3 |"
    "+---+---+---+"
    "| 4         |"
    "+---+---+---+"
);

Implementations§

Source§

impl Span

Source

pub fn column(size: isize) -> ColumnSpan

New constructs a horizontal/column Span.

Value can be: * == 0 - which means spread the cell on the whole line * == 1 - which is a default span so can be used for removal of spans * > 1 - which means to spread a cell by given number of columns right * < 0 - which means to spread a cell by given number of columns left

§Example
use tabled::{settings::{Span, Modify}, Table};

let data = [[1, 2, 3], [4, 5, 6]];

let table = Table::new(data)
    .modify((0, 0), Span::column(100))
    .modify((1, 1), Span::column(2))
    .modify((2, 1), Span::column(-1))
    .to_string();

assert_eq!(
    table,
    concat!(
        "+---++---+\n",
        "| 0      |\n",
        "+---++---+\n",
        "| 1 | 2  |\n",
        "+---++---+\n",
        "| 5  | 6 |\n",
        "+---++---+",
    )
)
Source

pub fn row(size: isize) -> RowSpan

New constructs a vertical/row Span.

Value can be: * == 0 - which means spread the cell on the whole line * == 1 - which is a default span so can be used for removal of spans * > 1 - which means to spread a cell by given number of rows bottom * < 0 - which means to spread a cell by given number of rows top

§Example
use tabled::{settings::{Span, Modify}, Table};

let data = [[1, 2, 3], [4, 5, 6]];

let table = Table::new(data)
    .modify((0, 0), Span::row(100))
    .modify((1, 1), Span::row(2))
    .modify((2, 2), Span::row(-1))
    .to_string();

assert_eq!(
    table,
    concat!(
        "+---+---+---+\n",
        "| 0 | 1 | 2 |\n",
        "+   +---+---+\n",
        "+   + 2 + 6 +\n",
        "+---+---+---+",
    )
)

Trait Implementations§

Source§

impl Debug for Span

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Span

§

impl RefUnwindSafe for Span

§

impl Send for Span

§

impl Sync for Span

§

impl Unpin for Span

§

impl UnwindSafe for Span

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