#world #produce #indentation #newlines #crlf #if-expr

nesty

Generate code with with human readable indentation

2 unstable releases

0.2.0 Aug 9, 2022
0.1.0 Aug 6, 2021

#1155 in Text processing

Download history 362/week @ 2024-12-08 621/week @ 2024-12-15 83/week @ 2024-12-22 705/week @ 2024-12-29 378/week @ 2025-01-05 303/week @ 2025-01-12 537/week @ 2025-01-19 404/week @ 2025-01-26 1058/week @ 2025-02-02 457/week @ 2025-02-09 895/week @ 2025-02-16 611/week @ 2025-02-23 526/week @ 2025-03-02 480/week @ 2025-03-09 522/week @ 2025-03-16 662/week @ 2025-03-23

2,265 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
~44K SLoC