Struct comfy_table::Column[][src]

pub struct Column {
    pub index: usize,
    // some fields omitted
}
Expand description

A representation of a table’s column. Useful for styling and specifying constraints how big a column should be.

  1. Content padding for cells in this column
  2. Constraints on how wide this column shall be
  3. Default alignment for cells in this column

Columns are generated when adding rows or a header to a table.
As a result columns can only be modified after the table is populated by some data.

use comfy_table::{Table, ColumnConstraint, CellAlignment};

let mut table = Table::new();
table.set_header(&vec!["one", "two"]);

let mut column = table.get_column_mut(1).expect("This should be column two");

// Set the max width for all cells of this column to 20 characters.
column.set_constraint(ColumnConstraint::MaxWidth(20));

// Set the left padding to 5 spaces and the right padding to 1 space
column.set_padding((5, 1));

// Align content in all cells of this column to the center of the cell.
column.set_cell_alignment(CellAlignment::Center);

Fields

index: usize

The index of the column

Implementations

Set the padding for all cells of this column.

Padding is provided in the form of (left, right).
Default is (1, 1).

Set the delimiter used to split text for this column’s cells.

A custom delimiter on a cell in will overwrite the column’s delimiter. Normal text uses spaces ( ) as delimiters. This is necessary to help comfy-table understand the concept of words.

Get the width in characters of the widest line in this column.
This doesn’t include padding yet!

Get the maximum possible width for this column.
This means widest line in this column + padding

Constraints allow to influence the auto-adjustment behavior of columns.
This can be useful to counter undesired auto-adjustment of content in tables.

Get the constraint that is used for this column.

Remove any constraint on this column

Set the alignment for content inside of cells for this column.
Note: Alignment on a cell will always overwrite the column’s setting.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.