2 unstable releases

0.2.0 Aug 9, 2022
0.1.0 Aug 6, 2021

#204 in Value formatting

Download history 197/week @ 2024-07-27 421/week @ 2024-08-03 292/week @ 2024-08-10 304/week @ 2024-08-17 262/week @ 2024-08-24 108/week @ 2024-08-31 127/week @ 2024-09-07 264/week @ 2024-09-14 386/week @ 2024-09-21 336/week @ 2024-09-28 215/week @ 2024-10-05 247/week @ 2024-10-12 178/week @ 2024-10-19 318/week @ 2024-10-26 330/week @ 2024-11-02 168/week @ 2024-11-09

1,018 downloads per month
Used in tomldoc

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
~53K SLoC