6 releases (breaking)

0.5.0 Nov 22, 2024
0.4.0 Aug 5, 2024
0.3.0 Dec 20, 2023
0.2.1 Jun 2, 2023
0.1.0 Apr 11, 2023

#1912 in Text processing

Download history 10/week @ 2024-09-16 12/week @ 2024-09-30 6/week @ 2024-10-07 118/week @ 2024-11-18 20/week @ 2024-11-25 13/week @ 2024-12-02 6/week @ 2024-12-09

157 downloads per month

MIT license

1MB
17K SLoC

(static_table) Cook tables at compiler time

The library provides a macros to build a pretty tables at compile time.

There's 2 types of tables you can build.

  1. Standard adjusted tables (static_table::static_table).
  2. Not adjusted, floating tables (static_table::pool_table).

To find a more features and settings which you can use with the macros please check out the documentation (docs.rs).

Get started

Add the library to your Cargo.toml.

# Cargo.toml
[dependencies]
static_table = "0.2"

An example of static_table usage.

Example Result
use static_table::static_table;

static LANG_LIST: &str = static_table!([
    ["name", "designed by", "first release"],
    ["C", "Dennis Ritchie", "1972"],
    ["Go", "Rob Pike", "2009"],
    ["Rust", "Graydon Hoare", "2010"],
    ["Hare", "Drew DeVault", "2022"],
]);

fn main() {
    println!("{LANG_LIST}")
}
+------+----------------+---------------+
| name | designed by    | first release |
+------+----------------+---------------+
| C    | Dennis Ritchie | 1972          |
+------+----------------+---------------+
| Go   | Rob Pike       | 2009          |
+------+----------------+---------------+
| Rust | Graydon Hoare  | 2010          |
+------+----------------+---------------+
| Hare | Drew DeVault   | 2022          |
+------+----------------+---------------+

An example of pool_table usage.

Example Result
use static_table::pool_table;

static LANG_LIST: &str = pool_table!([
    ["name", "designed by", "first release"],
    ["C", "Dennis Ritchie", "1972"],
    ["Go", "Rob Pike", "2009"],
    ["Rust", "Graydon Hoare", "2010"],
    ["Hare", "Drew DeVault", "2022"],
]);

fn main() {
    println!("{LANG_LIST}")
}
+------+-------------+---------------+
| name | designed by | first release |
+------+-------------+-----+---------+
| C    | Dennis Ritchie    | 1972    |
+------+--+---------------++---------+
| Go      | Rob Pike      | 2009     |
+---------+---------------+-+--------+
| Rust    | Graydon Hoare   | 2010   |
+---------+-----------------+--------+
| Hare    | Drew DeVault    | 2022   |
+---------+-----------------+--------+

You can even use the macros in the documentation

/// Add joins 2 integers together to get a sum.
/// 
/// ```
#[doc = static_table::static_table!([
    ["a", "b", "result"],
    ["1", '2', '3'],
    ["2", '2', '4']
])]
/// ```
pub fn add(left: usize, right: usize) -> usize {
    left + right
}

Binary size concern

It's something you shall be aware of. Using static_table MIGHT increase a binary size, because the table will be stored as actual symbols in a static section of a binary file (ELF, PE etc.).

I have run a few tests in this regard. And a binary which used static_table has SUBSTATIANALY smaller size than a binary with a build table at runtime using lazy_static/once_cell. I am not sure though why it is a case.

                debug mode      release mode
static_table    13497232        4501576
runtime table   12031120        4156024

Dependencies

~3.5MB
~72K SLoC