tabled

Struct Height

Source
pub struct Height;
Expand description

Height is a abstract factory for height settings.

§Example

use tabled::{Table, Height};

let data = vec![
    ("Some data", "here", "and here"),
    ("Some data on a next", "line", "right here"),
];

let table = Table::new(data)
    .with(Height::increase(10))
    .with(Height::limit(10))
    .to_string();

assert_eq!(
    table,
    "+---------------------+------+------------+\n\
     | &str                | &str | &str       |\n\
     |                     |      |            |\n\
     +---------------------+------+------------+\n\
     | Some data           | here | and here   |\n\
     |                     |      |            |\n\
     +---------------------+------+------------+\n\
     | Some data on a next | line | right here |\n\
     |                     |      |            |\n\
     +---------------------+------+------------+",
)

Implementations§

Source§

impl Height

Source

pub fn increase<W>(width: W) -> CellHeightIncrease<W>
where W: Measurment<Height>,

Create CellHeightIncrease to set a table/cell height.

§Example
§Cell height
use tabled::{Table, Height, Modify, object::Columns};

let data = vec![
    ("Some data", "here", "and here"),
    ("Some data on a next", "line", "right here"),
];

let table = Table::new(data)
    .with(Modify::new(Columns::first()).with(Height::increase(5)))
    .to_string();

assert_eq!(
    table,
    "+---------------------+------+------------+\n\
     | &str                | &str | &str       |\n\
     |                     |      |            |\n\
     |                     |      |            |\n\
     |                     |      |            |\n\
     |                     |      |            |\n\
     +---------------------+------+------------+\n\
     | Some data           | here | and here   |\n\
     |                     |      |            |\n\
     |                     |      |            |\n\
     |                     |      |            |\n\
     |                     |      |            |\n\
     +---------------------+------+------------+\n\
     | Some data on a next | line | right here |\n\
     |                     |      |            |\n\
     |                     |      |            |\n\
     |                     |      |            |\n\
     |                     |      |            |\n\
     +---------------------+------+------------+"
)
§Table height
use tabled::{Table, Height};

let data = vec![
    ("Some data", "here", "and here"),
    ("Some data on a next", "line", "right here"),
];

let table = Table::new(data)
    .with(Height::increase(10))
    .to_string();

assert_eq!(
    table,
    "+---------------------+------+------------+\n\
     | &str                | &str | &str       |\n\
     |                     |      |            |\n\
     +---------------------+------+------------+\n\
     | Some data           | here | and here   |\n\
     |                     |      |            |\n\
     +---------------------+------+------------+\n\
     | Some data on a next | line | right here |\n\
     |                     |      |            |\n\
     +---------------------+------+------------+",
)
Source

pub fn limit<W>(width: W) -> CellHeightLimit<W>
where W: Measurment<Height>,

Create CellHeightLimit to set a table/cell height.

§Example
§Cell height
use tabled::{Table, Height, Modify, object::Columns};

let data = vec![
    ("Some\ndata", "here", "and here"),
    ("Some\ndata on a next", "line", "right here"),
];

let table = Table::new(data)
    .with(Modify::new(Columns::first()).with(Height::limit(1)))
    .to_string();

assert_eq!(
    table,
    "+------+------+------------+\n\
     | &str | &str | &str       |\n\
     +------+------+------------+\n\
     | Some | here | and here   |\n\
     +------+------+------------+\n\
     | Some | line | right here |\n\
     +------+------+------------+"
)
§Table height
use tabled::{Table, Height};

let data = vec![
    ("Some\ndata", "here", "and here"),
    ("Some\ndata on a next", "line", "right here"),
];

let table = Table::new(&data)
    .with(Height::limit(6))
    .to_string();

assert_eq!(
    table,
    "+----------------+------+------------+\n\
     +----------------+------+------------+\n\
     | Some           | here | and here   |\n\
     +----------------+------+------------+\n\
     | Some           | line | right here |\n\
     +----------------+------+------------+",
);

let table = Table::new(&data)
    .with(Height::limit(1))
    .to_string();

assert_eq!(
    table,
    "+----------------+------+------------+\n\
     +----------------+------+------------+\n\
     +----------------+------+------------+\n\
     +----------------+------+------------+",
);
Source

pub fn list<I>(rows: I) -> HeightList
where I: IntoIterator<Item = usize>,

Create HeightList to set a table height to a constant list of row heights.

Notice if you provide a list with .len() less than Table::count_rows then it will have no affect.

§Example
use tabled::{Table, Height, Modify, object::Columns};

let data = vec![
    ("Some\ndata", "here", "and here"),
    ("Some\ndata on a next", "line", "right here"),
];

let table = Table::new(data)
    .with(Height::list([1, 0, 2]))
    .to_string();

assert_eq!(
    table,
    "+----------------+------+------------+\n\
     | &str           | &str | &str       |\n\
     +----------------+------+------------+\n\
     +----------------+------+------------+\n\
     | Some           | line | right here |\n\
     | data on a next |      |            |\n\
     +----------------+------+------------+",
)

Trait Implementations§

Source§

impl Debug for Height

Source§

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

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

impl Measurment<Height> for Max

Source§

fn measure<R>(&self, records: R, _: &GridConfig) -> usize
where R: Records,

Returns a measurment value.
Source§

impl Measurment<Height> for Min

Source§

fn measure<R>(&self, records: R, _: &GridConfig) -> usize
where R: Records,

Returns a measurment value.
Source§

impl Measurment<Height> for Percent

Source§

fn measure<R>(&self, records: R, cfg: &GridConfig) -> usize
where R: Records,

Returns a measurment value.

Auto Trait Implementations§

§

impl Freeze for Height

§

impl RefUnwindSafe for Height

§

impl Send for Height

§

impl Sync for Height

§

impl Unpin for Height

§

impl UnwindSafe for Height

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.