Struct cli_tables::Table

source ·
pub struct Table { /* private fields */ }

Implementations§

source§

impl Table

source

pub fn new() -> Self

source

pub fn push_row(&mut self, new_record: &Vec<&str>) -> Result<(), PushError>

Description

Pushes a new row/record to the table.

Arguments
  • new_record - An immutable reference to a vector of string slices representing the new record. In Rust, the &str type represents a string slice. It is an immutable reference to a string data stored elsewhere, typically UTF-8 encoded. String slices are commonly used to efficiently work with string data without taking ownership of it.
Errors

Returns an error if the number of fields is invalid.

Examples
use cli_tables::{Table, PushError};
 
let mut table = Table::new(); // creates a new table

let header = vec!["Id", "Title", "Series", "Author"]; // add rows using a vector of string slices
assert_eq!(table.push_row(&header), Ok(())); // handle errors
 
let book = vec!["0", "Sword of Destiny", "The Witcher Series", "Andrzej Sapkowski"];
assert_eq!(table.push_row(&book), Ok(()));

let invalid_record = vec!["1", "The Last Wish", "The Witcher Series"];
assert_eq!(
    table.push_row(&invalid_record),
    Err(PushError {
        message: "Invalid number of fields in record. Found 3, but expected 4.".to_string()
    })
);
source

pub fn to_string(&self) -> String

Trait Implementations§

source§

impl Debug for Table

source§

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

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

impl Display for Table

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Table

§

impl Send for Table

§

impl Sync for Table

§

impl Unpin for Table

§

impl UnwindSafe for Table

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.