#string-literal #string #compile-time #proc-macro #literals #indentation #remove

macro str-block

Remove the initial newline and common indentation from string literals

3 releases

0.1.2 Mar 21, 2024
0.1.1 Feb 17, 2024
0.1.0 Feb 16, 2024

#1029 in Text processing

Download history 282/week @ 2024-02-12 55/week @ 2024-02-19 29/week @ 2024-02-26 24/week @ 2024-03-11 110/week @ 2024-03-18 18/week @ 2024-03-25 30/week @ 2024-04-01

182 downloads per month

MIT OR Apache-2.0 OR Zlib

155KB
3.5K SLoC

str-block

str_block is a proc macro for processing string literals. It removes the first line from its input if it's empty except for whitespace, and removes common indentation from the rest of the lines. Lines that are empty except for whitespace are treated as if they have the common indentation.

# use str_block::str_block;
assert_eq!(str_block! {"
    Hello
    World
"}, "Hello\nWorld\n");

Use with {} to stop rustfmt from moving around your string.

You can pass multiple string literals to str_block, and it'll concatenate them for you before processing the result. You can also pass raw string literals.

Dependencies

~65KB