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

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

#1134 in Text processing

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

~55KB