Skip to main content

Cell

Struct Cell 

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

A single table cell.

Implementations§

Source§

impl Cell

Source

pub fn new(content: impl Into<Text>) -> Self

Creates a cell from content.

Examples found in repository?
examples/output_gallery.rs (line 112)
105fn tables() -> Result<()> {
106    section("Tables")?;
107    Table::new()
108        .title("Servers")
109        .columns(["Name", "Region", "Status"])
110        .row(["web-1", "eu-west", "online"])
111        .row(["db-1", "eu-west", "online"])
112        .row([Cell::new("maintenance window")
113            .colspan(3)
114            .align(Align::Center)])
115        .striped(true)
116        .print()?;
117    println!();
118    Table::new()
119        .columns([
120            Column::new("Item").align(Align::Left),
121            Column::new("Note").wrap().max_width(24),
122        ])
123        .row([
124            "alpha",
125            "a long note that wraps across several lines nicely",
126        ])
127        .row(["beta", "short note"])
128        .footer_row([Cell::new("2 items").colspan(2).align(Align::Right)])
129        .border(BorderType::Ascii)
130        .print()?;
131    Ok(())
132}
More examples
Hide additional examples
examples/output-readme.rs (line 76)
74fn overview_table() -> Rendered {
75    let status = |text: &str, color: Color| {
76        Cell::new(Text::styled(text, Style::new().fg(color).bold()))
77    };
78    Table::new()
79        .title("Overview")
80        .title_style(Style::new().fg(Color::Magenta).bold())
81        .border(BorderType::Rounded)
82        .border_style(Style::new().fg(Color::Magenta))
83        .header_style(Style::new().fg(Color::Cyan).bold())
84        .striped(true)
85        .stripe_style(Style::new().bg(Color::Rgb(40, 40, 60)))
86        .row_separators(true)
87        .columns([
88            Column::new("Service"),
89            Column::new("Status").align(Align::Center),
90            Column::new("Uptime").align(Align::Right),
91        ])
92        .row([
93            Cell::new("api-gateway"),
94            status("● OK", Color::Green),
95            Cell::new("99.98%"),
96        ])
97        .row([
98            Cell::new("auth"),
99            status("● OK", Color::Green),
100            Cell::new("99.91%"),
101        ])
102        .row([
103            Cell::new("billing"),
104            status("● WARN", Color::Yellow),
105            Cell::new("97.40%"),
106        ])
107        .row([
108            Cell::new("scheduler"),
109            status("● FAIL", Color::Red),
110            Cell::new("82.10%"),
111        ])
112        .render(40)
113}
Source

pub fn align(self, align: Align) -> Self

Overrides the cell alignment.

Examples found in repository?
examples/output_gallery.rs (line 114)
105fn tables() -> Result<()> {
106    section("Tables")?;
107    Table::new()
108        .title("Servers")
109        .columns(["Name", "Region", "Status"])
110        .row(["web-1", "eu-west", "online"])
111        .row(["db-1", "eu-west", "online"])
112        .row([Cell::new("maintenance window")
113            .colspan(3)
114            .align(Align::Center)])
115        .striped(true)
116        .print()?;
117    println!();
118    Table::new()
119        .columns([
120            Column::new("Item").align(Align::Left),
121            Column::new("Note").wrap().max_width(24),
122        ])
123        .row([
124            "alpha",
125            "a long note that wraps across several lines nicely",
126        ])
127        .row(["beta", "short note"])
128        .footer_row([Cell::new("2 items").colspan(2).align(Align::Right)])
129        .border(BorderType::Ascii)
130        .print()?;
131    Ok(())
132}
Source

pub fn colspan(self, columns: usize) -> Self

Spans this cell across columns columns.

Examples found in repository?
examples/output_gallery.rs (line 113)
105fn tables() -> Result<()> {
106    section("Tables")?;
107    Table::new()
108        .title("Servers")
109        .columns(["Name", "Region", "Status"])
110        .row(["web-1", "eu-west", "online"])
111        .row(["db-1", "eu-west", "online"])
112        .row([Cell::new("maintenance window")
113            .colspan(3)
114            .align(Align::Center)])
115        .striped(true)
116        .print()?;
117    println!();
118    Table::new()
119        .columns([
120            Column::new("Item").align(Align::Left),
121            Column::new("Note").wrap().max_width(24),
122        ])
123        .row([
124            "alpha",
125            "a long note that wraps across several lines nicely",
126        ])
127        .row(["beta", "short note"])
128        .footer_row([Cell::new("2 items").colspan(2).align(Align::Right)])
129        .border(BorderType::Ascii)
130        .print()?;
131    Ok(())
132}
Source

pub fn rowspan(self, rows: usize) -> Self

Spans this cell across rows rows.

Cells in the rows below skip the spanned column(s); content sits in the top row. Best paired with the default (no row separators).

Trait Implementations§

Source§

impl From<&str> for Cell

Source§

fn from(value: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Cell

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl From<Text> for Cell

Source§

fn from(value: Text) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Cell

§

impl RefUnwindSafe for Cell

§

impl Send for Cell

§

impl Sync for Cell

§

impl Unpin for Cell

§

impl UnsafeUnpin for Cell

§

impl UnwindSafe for Cell

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> 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, 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.