Skip to main content

TextTable

Struct TextTable 

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

Table of parsed CLI output with named columns.

Implementations§

Source§

impl TextTable

Source

pub fn new(header: Vec<String>) -> TextTable

Create a new empty table with the given header.

Source

pub fn from_values(header: Vec<String>, values: Vec<Vec<Value>>) -> TextTable

Create a table from header and value rows.

Source

pub fn header(&self) -> &[String]

Get the header (column names).

Source

pub fn len(&self) -> usize

Get the number of rows.

Source

pub fn is_empty(&self) -> bool

Check if the table is empty.

Source

pub fn superkey(&self) -> &[String]

Get the superkey columns.

Source

pub fn set_superkey(&mut self, keys: Vec<String>)

Set the superkey columns for sorting.

Source

pub fn add_keys(&mut self, keys: &[String])

Add key columns to the superkey.

Source

pub fn append(&mut self, values: Vec<Value>)

Append a row to the table.

Source

pub fn append_row(&mut self, row: Row)

Append a Row object.

Source

pub fn remove(&mut self, index: usize) -> Option<Row>

Remove a row by index.

Source

pub fn get(&self, index: usize) -> Option<&Row>

Get a row by index.

Source

pub fn get_mut(&mut self, index: usize) -> Option<&mut Row>

Get a mutable row by index.

Source

pub fn iter(&self) -> impl Iterator<Item = &Row>

Iterate over rows.

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Row>

Iterate over mutable rows.

Source

pub fn filter<F>(&self, predicate: F) -> TextTable
where F: Fn(&Row) -> bool,

Filter rows by a predicate.

Source

pub fn sort(&mut self)

Sort by superkey (if set) or by first column. Uses natural sorting (numeric values sorted numerically, strings alphabetically).

Source

pub fn sort_by_key<K, F>(&mut self, f: F)
where K: Ord, F: Fn(&Row) -> K,

Sort by a key function.

Source

pub fn sort_by<F>(&mut self, compare: F)
where F: Fn(&Row, &Row) -> Ordering,

Sort by a comparison function.

Source

pub fn row_with(&self, column: &str, value: &str) -> Option<&Row>

Find the first row where a column has a specific value.

Source

pub fn formatted(&self) -> String

Get formatted table output.

Source

pub fn to_csv(&self) -> String

Convert to CSV format.

Source

pub fn into_values(self) -> Vec<Vec<Value>>

Convert to Vec<Vec> for serde compatibility.

Source

pub fn values(&self) -> impl Iterator<Item = &Vec<Value>>

Get the raw values as references.

Source

pub fn clear(&mut self)

Clear all rows.

Trait Implementations§

Source§

impl Clone for TextTable

Source§

fn clone(&self) -> TextTable

Returns a duplicate 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 TextTable

Source§

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

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

impl Display for TextTable

Source§

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

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

impl<'a> IntoIterator for &'a TextTable

Source§

type Item = &'a Row

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Row>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <&'a TextTable as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for TextTable

Source§

type Item = Row

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<Row>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> <TextTable as IntoIterator>::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

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, 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.