comfy_table

Struct Column

Source
pub struct Column {
    pub index: usize,
    /* private fields */
}
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::{Width::*, CellAlignment, ColumnConstraint::*, Table};

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

let mut column = table.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(UpperBoundary(Fixed(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§

Source§

impl Column

Source

pub fn new(index: usize) -> Self

Source

pub fn set_padding(&mut self, padding: (u16, u16)) -> &mut Self

Set the padding for all cells of this column.

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

Source

pub fn padding_width(&self) -> u16

Convenience helper that returns the total width of the combined padding.

Source

pub fn set_delimiter(&mut self, delimiter: char) -> &mut Self

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.

Source

pub fn set_constraint(&mut self, constraint: ColumnConstraint) -> &mut Self

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

Source

pub fn constraint(&self) -> Option<&ColumnConstraint>

Get the constraint that is used for this column.

Source

pub fn remove_constraint(&mut self) -> &mut Self

Remove any constraint on this column

Source

pub fn is_hidden(&self) -> bool

Returns weather the columns is hidden via ColumnConstraint::Hidden.

Source

pub fn set_cell_alignment(&mut self, alignment: CellAlignment)

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§

Source§

impl Clone for Column

Source§

fn clone(&self) -> Column

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Column

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Column

§

impl RefUnwindSafe for Column

§

impl Send for Column

§

impl Sync for Column

§

impl Unpin for Column

§

impl UnwindSafe for Column

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, dst: *mut T)

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