2 unstable releases

0.2.0 Aug 9, 2022
0.1.0 Aug 6, 2021

#205 in Value formatting

Download history 168/week @ 2023-10-31 171/week @ 2023-11-07 74/week @ 2023-11-14 83/week @ 2023-11-21 166/week @ 2023-11-28 144/week @ 2023-12-05 156/week @ 2023-12-12 49/week @ 2023-12-19 58/week @ 2023-12-26 167/week @ 2024-01-02 120/week @ 2024-01-09 112/week @ 2024-01-16 175/week @ 2024-01-23 190/week @ 2024-01-30 146/week @ 2024-02-06 195/week @ 2024-02-13

751 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–9.5MB
~59K SLoC