2 unstable releases

0.2.0 Aug 9, 2022
0.1.0 Aug 6, 2021

#181 in Value formatting

Download history 120/week @ 2024-03-14 252/week @ 2024-03-21 149/week @ 2024-03-28 106/week @ 2024-04-04 120/week @ 2024-04-11 220/week @ 2024-04-18 127/week @ 2024-04-25 221/week @ 2024-05-02 133/week @ 2024-05-09 144/week @ 2024-05-16 141/week @ 2024-05-23 229/week @ 2024-05-30 150/week @ 2024-06-06 328/week @ 2024-06-13 265/week @ 2024-06-20 427/week @ 2024-06-27

1,193 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–11MB
~64K SLoC