Crate simple_tables[][src]

Expand description

The simple tables crate allows you to easily create table structures.

Getting started

You can use the macros table_row and table to make a new table with the row structure defined by your table rows.

Example


#[table_row]
struct MyTableRow {
  id: u32,
  name: String,
  email: String,
  address: String
}

#[table(rows = MyTableRow)]
struct MyTable {}

Examples

Printing out a table

You can use the to_string() method to convert a table to a formatted text table and then print it out.


let rows: Vec<MyTableRow> = vec![
  MyTableRow{ id: 0, name: "David Bowie".to_string(), email: "david@bowie.com".to_string(), address: "England".to_string()},
  MyTableRow{ id: 1, name: "David Gilmour".to_string(), email: "david@gilmour.com".to_string(), address: "England".to_string()},
  MyTableRow{ id: 2, name: "Opeth".to_string(), email: "info@opeth.com".to_string(), address: "Sweden".to_string()},
  MyTableRow{ id: 3, name: "The Beatles".to_string(), email: "info@beatles.com".to_string(), address: "England".to_string()}
];

let table = MyTable::from_vec(&rows);
let s = table.to_string();
println!("{}", s);

The output will be:

+----+---------------+-------------------+---------+
| id | name          | email             | address |
+====+===============+===================+=========+
| 0  | David Bowie   | david@bowie.com   | England |
+----+---------------+-------------------+---------+
| 1  | David Gilmour | david@gilmour.com | England |
+----+---------------+-------------------+---------+
| 2  | Opeth         | info@opeth.com    | Sweden  |
+----+---------------+-------------------+---------+
| 3  | The Beatles   | info@beatles.com  | England |
+----+---------------+-------------------+---------+

More examples can be found on GitHub.

Traits

Macros

Re-exports

pub extern crate simple_tables_core as core;
pub extern crate simple_tables_derive as derive;

Modules

Traits

Defines a table with a unique identifier. This class should be implemented alongside the Table trait.

A table should conform to this trait. Row is the table’s row type.