Crate dedent

Source
Expand description

A procedural macro for automatically removing common leading whitespace from multi-line strings.

§Usage

use dedent::dedent;

let formatted = dedent!(r#"
    Hello
      World
        !"#);

assert_eq!(formatted, "Hello\n  World\n    !");

§How it works

The macro:

  1. Splits the input string into lines
  2. Finds the minimum indentation level among non-empty lines
  3. Removes that amount of whitespace from the start of each non-empty line
  4. Removes leading and trailing empty lines

Macros§

dedent
Removes common leading whitespace from a multi-line string literal.