Struct Table

Source
pub struct Table { /* private fields */ }

Implementations§

Source§

impl Table

Source

pub fn new() -> Self

Source

pub fn num_records(&self) -> usize

Source

pub fn num_fields(&self) -> usize

Source

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

§Description

Pushes a new record to the end of the Table object.

§Arguments
  • new_record: &Vec<&str> - An immutable reference to string slices that represent the new record.
§Errors

Returns an error if the number of fields is invalid.

§Example
use cli_tables::Table;
 
let mut table = Table::new();

let header = vec!["Id", "Title", "Series", "Author"];
table.push_row(&header).unwrap();
 
let book = vec!["0", "Sword of Destiny", "The Witcher Series", "Andrzej Sapkowski"];
table.push_row(&book).unwrap();
Source

pub fn push_row_string( &mut self, new_record: &Vec<String>, ) -> Result<(), TableError>

§Description

Pushes a new record to the end of the Table object.

§Arguments
  • new_record: &Vec<String> - An immutable reference to Strings that represent the new record.
§Errors

Returns an error if the number of fields is invalid.

§Example
use cli_tables::Table;
 
let mut table = Table::new();

let header = vec![
    "Id".to_string(), 
    "Title".to_string(), 
    "Series".to_string(), 
    "Author".to_string()
];
table.push_row_string(&header).unwrap();
 
let book = vec![
    "0".to_string(), 
    "Sword of Destiny".to_string(), 
    "The Witcher Series".to_string(), 
    "Andrzej Sapkowski".to_string()
];
table.push_row_string(&book).unwrap();
Source

pub fn push_rows( &mut self, new_records: &Vec<Vec<&str>>, ) -> Result<(), TableError>

§Description

The push_rows function takes multiple records, and adds each one in order to the Table object.

§Arguments
  • new_records - reference to a Vec<Vec<&str>> object that represents multiple records.
§Errors

Returns a TableError if the number of fields is not equal for each record or if the number of fields is not equal to the existing number of fields in the Table object.

§Example
use cli_tables::Table;
 
let mut table = Table::new();

let table_vec = vec![
    vec!["Id", "Title", "Series", "Author"],
    vec!["0", "Sword of Destiny", "The Witcher Series", "Andrzej Sapkowski"],
    vec!["1", "The Last Wish", "The Witcher Series", "Andrzej Sapkowski"]
];
table.push_rows(&table_vec).unwrap();
Source

pub fn get_row(&self, id: usize) -> Result<Vec<String>, TableError>

§Description

Retrieves the desired record of the Table object and returns it.

§Arguments
  • id: usize - represets the desired record id to be retrieved.
§Errors

Returns a TableError if no record with the given id is found.

§Example
use cli_tables::Table;
 
let mut table = Table::new();

let header = vec![
    "Id",
    "Title",
    "Series",
    "Author"
];
table.push_row(&header).unwrap();
 
table.get_row(0).unwrap();
Source

pub fn delete_record(&mut self, id: usize) -> Result<(), TableError>

§Description

Deletes the desired record from the Table object.

§Arguments
  • id - A usize value that represets the desired record id to be deleted.
§Errors

Returns a TableError if no record with the given id is found.

§Example
use cli_tables::Table;
 
let mut table = Table::new();

let header = vec![
    "Id",
    "Title",
    "Series",
    "Author"
];
table.push_row(&header).unwrap();
 
table.delete_record(0).unwrap();
Source

pub fn set(&mut self, new_table: &Vec<Vec<&str>>) -> Result<(), TableError>

§Description

The set function takes multiple records, and adds each one in order to the Table object. If the Table object is not empty, it is reset with the given values.

§Arguments
  • new_table - reference to a Vec<Vec<&str>> object that represents multiple records.
§Errors

Returns a TableError if the number of fields is not equal for each record.

§Example
use cli_tables::Table;
 
let mut table = Table::new();

let table_vec = vec![
    vec!["Id", "Title", "Series", "Author"],
    vec!["0", "Sword of Destiny", "The Witcher Series", "Andrzej Sapkowski"],
    vec!["1", "The Last Wish", "The Witcher Series", "Andrzej Sapkowski"]
];
table.set(&table_vec).unwrap();
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 Freeze for Table

§

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