2 unstable releases

0.2.0 Aug 9, 2022
0.1.0 Aug 6, 2021

#203 in Value formatting

Download history 318/week @ 2024-10-26 330/week @ 2024-11-02 170/week @ 2024-11-09 193/week @ 2024-11-16 253/week @ 2024-11-23 298/week @ 2024-11-30 375/week @ 2024-12-07 591/week @ 2024-12-14 98/week @ 2024-12-21 713/week @ 2024-12-28 303/week @ 2025-01-04 311/week @ 2025-01-11 558/week @ 2025-01-18 447/week @ 2025-01-25 890/week @ 2025-02-01 604/week @ 2025-02-08

2,579 downloads per month
Used in 4 crates (2 directly)

MIT/Apache

10KB
188 lines

Nesty

A small crate to help generate human readable code from rust.

The primary interface is the code! macro which looks as follows:

code!{
    [0] "fn main() {";
    [1]     "println!(\"hello, world\");";
    [0] "}"
}

The bracketed numbers give the desired amount of indentation for the line.

Code blocks can also be nested, like so:

let if_expr = code!{
    [0] "if x > 0 {";
    [1]     "println(\"found one!\")";
    [0] "}"
}
code!{
    [0] "fn main() {";
    [1]     if_expr;
    [0] "}"
}

which will produce

fn main() {
    if x > 0 {
        println!("found one!");
    }
}

The code macro also supports strings, and vectors of strings which will be properly indented, (vectors are assumed to be a vector of lines, strings are indented after each newline)

With the diff_assert feature, the crate also has a assert_same_code macro which checks two strings for equality, and if they differ, prints a diff before panicing.

Dependencies

~0–7.5MB
~45K SLoC