pub struct Column { /* private fields */ }Expand description
A column definition: a header, core ColumnOptions and an optional
formatter.
use rich::{Justify, Text};
use rich_ext::table::{Column, Value};
let size = Column::new("size")
.justify(Justify::Right)
.format(|v| match v.as_f64() {
Some(n) => Text::new(rich_ext::format::bytes(n as u64)),
None => Text::new(""),
});
assert_eq!(size.cell(&Value::Int(2048)).plain(), "2.0 kB");Implementations§
Source§impl Column
impl Column
Sourcepub fn new(header: impl Into<String>) -> Self
pub fn new(header: impl Into<String>) -> Self
A left-justified column. The header is literal text, not markup.
Sourcepub fn options(self, options: ColumnOptions) -> Self
pub fn options(self, options: ColumnOptions) -> Self
Replace every core column option (width, ratio, no_wrap, style, …).
Sourcepub fn format(
self,
formatter: impl Fn(&Value) -> Text + Send + Sync + 'static,
) -> Self
pub fn format( self, formatter: impl Fn(&Value) -> Text + Send + Sync + 'static, ) -> Self
Display values through formatter instead of Value::to_text.
Aggregates other than counts are formatted the same way.
Sourcepub fn column_options(&self) -> &ColumnOptions
pub fn column_options(&self) -> &ColumnOptions
The core column options.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Column
impl !UnwindSafe for Column
impl Freeze for Column
impl Send for Column
impl Sync for Column
impl Unpin for Column
impl UnsafeUnpin for Column
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