Skip to main content

Table

Struct Table 

Source
pub struct Table { /* private fields */ }
Expand description

A table of rows under column headers.

A table measures its columns, gives each one a width, and renders every cell at its column’s width:

  1. Each column starts at the widest cell it holds.
  2. When those widths and the frame fit, the table is exactly that wide.
  3. Otherwise the widest column that can still shrink narrows by 1 cell of width, again and again. A keep-words column never goes below its widest word, and a fold column never goes below its widest cluster. An ellipsis column can shrink to a width of 1 cell.
  4. When the narrowest widths still do not fit, an unframed table lets its keep-words columns run past the width. A Frame::Grid table folds those columns instead, so its frame stays aligned. It folds only the columns that can fold alone to make it fit, so a short id keeps its word beside a long URL.
  5. Each cell renders at its column’s width. An ellipsis cell ends in …, and a numeric column aligns right.
  6. Each column then narrows to its widest rendered line. After a column wraps, its widest line fills its width, so no blank strip runs down the whole column. A table sized to its content draws no wider than it needs. An ellipsis column that cut a cell keeps its width, since the cut cell fills it.

Narrowing never changes the lines: text wrapped at a width wraps the same at its own widest line.

A table with no rows and no header draws nothing and measures 0.

Implementations§

Source§

impl Table

Source

pub fn new(columns: impl IntoIterator<Item = Column>) -> Self

A table with columns and no rows, drawn as a Frame::Grid with no separation between rows.

Source

pub fn frame(self, frame: Frame) -> Self

Sets what the table draws around and between its columns, replacing the default Frame::Grid.

Source

pub fn row_separation(self, separation: RowSeparation) -> Self

Sets what separates consecutive rows, replacing the default RowSeparation::None.

Source

pub fn row<C: Into<Text>>(self, cells: impl IntoIterator<Item = C>) -> Self

Adds a row of &str, String, Text, or anything else that converts to a Text.

The column’s overflow replaces the cell’s own. A row with fewer cells than the table has columns gets empty cells, and cells past the last column are dropped.

Source

pub fn rows<C, R>(self, rows: impl IntoIterator<Item = R>) -> Self
where R: IntoIterator<Item = C>, C: Into<Text>,

Adds every row of rows in order, as row adds one.

Trait Implementations§

Source§

impl Clone for Table

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Table

Source§

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

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

impl Renderable for Table

Source§

fn measure(&self, context: &Context) -> Measurement

The narrowest and widest this content can usefully be.
Source§

fn render(&self, context: &Context) -> Vec<Line>

Lines no wider than context.width(), except a word or cluster that the content’s overflow policy keeps whole.

Auto Trait Implementations§

§

impl Forget for Table

§

impl Freeze for Table

§

impl RefUnwindSafe for Table

§

impl Send for Table

§

impl Sync for Table

§

impl Unpin for Table

§

impl UnsafeUnpin for Table

§

impl UnwindSafe for Table

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.