pub struct Cell { /* private fields */ }Expand description
A single table cell.
Implementations§
Source§impl Cell
impl Cell
Sourcepub fn new(content: impl Into<Text>) -> Self
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
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}Sourcepub fn align(self, align: Align) -> Self
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}Sourcepub fn colspan(self, columns: usize) -> Self
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}Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more