2 unstable releases

0.2.0 Aug 9, 2022
0.1.0 Aug 6, 2021

#295 in Value formatting

Download history 154/week @ 2025-08-26 203/week @ 2025-09-02 128/week @ 2025-09-09 117/week @ 2025-09-16 174/week @ 2025-09-23 127/week @ 2025-09-30 133/week @ 2025-10-07 204/week @ 2025-10-14 378/week @ 2025-10-21 120/week @ 2025-10-28 287/week @ 2025-11-04 213/week @ 2025-11-11 209/week @ 2025-11-18 81/week @ 2025-11-25 473/week @ 2025-12-02 157/week @ 2025-12-09

1,065 downloads per month
Used in 7 crates (3 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–10MB
~58K SLoC