Skip to main content

Table

Struct Table 

Source
pub struct Table<Row = TextTableRow> { /* private fields */ }
Expand description

Owned table data independent of presentation policy.

Table owns semantic content, structural visibility, and offsets only. Every presentation concern — borders, padding, width, and cell styles — belongs to TablePresentation.

Rows may be ragged: a row shorter than the widest row is padded with empty cells when its TableRow formatting is composed. Use Table::text for rows that are already plain text.

use urushi::{BlockStyle, Table, TablePresentation, TextStyle, measure};

let table = Table::text()
    .headers(["Name", "Location"])
    .row(["Kini", "New York"])
    .row(["Iris", "Paris"]);

let presentation =
    TablePresentation::new(BlockStyle::new(), BlockStyle::new(), TextStyle::new());
assert_eq!(measure(&presentation.compose(&table)).height(), 6);

Implementations§

Source§

impl<Row> Table<Row>

Source

pub fn new() -> Self

Creates an empty table.

Source

pub fn headers<I, S>(self, headers: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Replaces the header cells, each of which is plain text.

A table without headers composes its body rows only. Escape sequences and cursor movement in a header break the plain-text contract: debug builds panic, and release builds measure them as ordinary characters and may split them when wrapping or truncating. Raw ANSI is not accepted as component text.

Source

pub fn row(self, row: Row) -> Self

Appends one body row.

Source

pub fn rows<I>(self, rows: I) -> Self
where I: IntoIterator<Item = Row>,

Appends typed body rows in iteration order.

Source

pub const fn hidden(self, hidden: bool) -> Self

Includes or excludes the complete table.

Source

pub const fn offset(self, start: usize, end: usize) -> Self

Omits start body rows from the front and end from the back.

Headers are never omitted; the offset selects among body rows only.

Source

pub const fn is_hidden(&self) -> bool

Returns whether the table is excluded.

Source§

impl<Row> Table<Row>
where Row: TableRow,

Source

pub fn column_count(&self) -> usize

Returns the column count from the widest canonical header or body row.

This formats every owned row, including rows omitted by the offset. Composition formats only visible rows, so an omitted wide row does not add columns to the composed view.

Source§

impl Table<TextTableRow>

Source

pub fn text() -> TextTable

Creates an empty table that accepts rows of direct plain text.

Trait Implementations§

Source§

impl<Row: Clone> Clone for Table<Row>

Source§

fn clone(&self) -> Table<Row>

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<Row: Debug> Debug for Table<Row>

Source§

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

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

impl<Row> Default for Table<Row>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<Row: PartialEq> PartialEq for Table<Row>

Source§

fn eq(&self, other: &Table<Row>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Row: Eq> Eq for Table<Row>

Source§

impl<Row> StructuralPartialEq for Table<Row>

Auto Trait Implementations§

§

impl<Row> Freeze for Table<Row>

§

impl<Row> RefUnwindSafe for Table<Row>
where Row: RefUnwindSafe,

§

impl<Row> Send for Table<Row>
where Row: Send,

§

impl<Row> Sync for Table<Row>
where Row: Sync,

§

impl<Row> Unpin for Table<Row>
where Row: Unpin,

§

impl<Row> UnsafeUnpin for Table<Row>

§

impl<Row> UnwindSafe for Table<Row>
where Row: 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, 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 = 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.