Skip to main content

TableView

Struct TableView 

Source
pub struct TableView<'a> { /* private fields */ }
Expand description

A sequence of records as a table.

Columns are the union of the records’ keys in first-seen order; a record that is not a map fills a value column. Missing cells stay empty, nested values show as compact JSON, numbers are right-justified and nulls dim. A map renders as one record; a scalar as a one-cell table.

use rich::Console;
use rich_ext::data::{from_serialize, TableView};
use serde_json::json;

let rows = from_serialize(&json!([{"name": "a", "port": 80}, {"name": "b"}])).unwrap();
let out = Console::builder().width(30).build().render_export(&TableView::new(&rows));
assert!(out.contains("│ a    │   80 │"), "{out}");

Implementations§

Source§

impl<'a> TableView<'a>

Source

pub fn new(node: impl Into<Cow<'a, Node>>) -> Self

Source

pub fn options(self, options: TableOptions) -> Self

Replace all options.

Source

pub fn columns<S: Into<String>>( self, columns: impl IntoIterator<Item = S>, ) -> Self

Source

pub fn header( self, column: impl Into<String>, header: impl Into<String>, ) -> Self

Source

pub fn justify(self, column: impl Into<String>, justify: Justify) -> Self

Source

pub fn title(self, title: impl Into<String>) -> Self

Source

pub fn max_rows(self, max_rows: usize) -> Self

Source

pub fn max_string(self, max_string: usize) -> Self

Source

pub fn to_table(&self, console: &Console) -> Table

The core table.

Trait Implementations§

Source§

impl<'a> Clone for TableView<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for TableView<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Renderable for TableView<'_>

Source§

fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>

Source§

fn measure(&self, _console: &Console, options: &ConsoleOptions) -> Measurement

The (minimum, maximum) cell width this renderable wants. The default assumes the renderable fills the available width (e.g. Panel, Table); Text overrides it with its content width so the top-level print path can shrink to fit. Port of __rich_measure__ / Measurement.get.
Source§

fn fit_to_measurement(&self) -> bool

Whether a top-level Console::print shrinks this renderable to its measured width. Upstream renders every top-level renderable at the full console width, so the default is false; an extension may opt in.
Source§

fn vertical(&self) -> Option<VerticalAlign>

The vertical alignment a Table cell holding this renderable uses in place of its column’s. Upstream reads getattr(renderable, "vertical", None); Align sets it.

Auto Trait Implementations§

§

impl<'a> Freeze for TableView<'a>

§

impl<'a> RefUnwindSafe for TableView<'a>

§

impl<'a> Send for TableView<'a>

§

impl<'a> Sync for TableView<'a>

§

impl<'a> Unpin for TableView<'a>

§

impl<'a> UnsafeUnpin for TableView<'a>

§

impl<'a> UnwindSafe for TableView<'a>

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more