Skip to main content

Table

Struct Table 

Source
pub struct Table {
    pub columns: Vec<TableColumn>,
    pub header_rows: u32,
    pub rows: Vec<Vec<TableCell>>,
    pub caption: Option<Vec<Inline>>,
    pub extra: Extra,
}
Expand description

A table: { "type": "table", "columns": …, "rows": … } in book.json (the block’s JSON is flat; Block::Table(Table)).

Fields§

§columns: Vec<TableColumn>

One entry per column: how its text is aligned. Its length is the table’s width.

§header_rows: u32

The first header_rows rows are headers (0: none). They repeat on every page in print and are <thead> in the EPUB.

§rows: Vec<Vec<TableCell>>

Row by row, only the cells that START in the row: a cell that a rowspan above covers is not listed again.

§caption: Option<Vec<Inline>>

Shown above the table.

§extra: Extra

Fields written by newer builds, kept on round-trip.

Implementations§

Source§

impl Table

Source

pub fn new( columns: Vec<TableColumn>, header_rows: u32, rows: Vec<Vec<TableCell>>, ) -> Self

A table, normalized (see Table::normalized): what the importers build. columns may be empty, then the width is the widest row’s.

Source

pub fn with_caption(self, caption: Vec<Inline>) -> Self

The same table with a caption shown above it.

Source

pub fn layout(&self) -> TableLayout<'_>

The grid this table means, by the seven rules below. Total: no stored table panics or loses a cell’s text.

  1. The width is columns.len() (or the widest row, see Self::width).
  2. A span of 0 is 1; a colspan is cut at the width and at a position a rowspan above covers.
  3. Cells are placed row by row, each at the first position at or after the end of the previous one that no rowspan above covers. A cell that does not fit has its text appended, after a line break, to the last cell placed in its row.
  4. A rowspan is cut at the last row and at the header boundary (a cell that starts in a header row covers header rows only). A rectangle cannot meet a position already taken: placement goes row by row, so positions below a cell are free until a later row takes them, and that row avoids the covered ones.
  5. A position nothing covers and no cell was placed on becomes an empty cell.
  6. A row whose every position is covered by rowspans from above cuts those spans to end above it, and is then placed like any row (its listed cells take the freed positions, the rest become empty). The ADR drops the text of such a row’s listed cells; this keeps it, since the rule only exists so that no row is without a cell.
  7. header_rows is cut to the number of rows.
Source

pub fn normalized(&self) -> Table

The layout written back as a stored table, in the form importers and Table::new make: one column entry per position, only the cells that start in each row, spans cut, gaps filled with empty cells, header_rows cut. Its layout is this table’s, cell for cell (the source of a cell made up now points at its stored place).

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 Default for Table

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Table

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Table

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for Table

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Table

Auto Trait Implementations§

§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.