jharrilim / dedent-macro-rs

Proc macro for dedenting string literals

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dedent-macro

This crate provides a simple compile-time macro to dedent strings. Useful for keeping consistent indentation within code.

Before:

fn write_win_status(x: bool) {
    let s = if x {
      "
Congratulations!
You won!
      "
    } else {
      "
Uh oh,
try again!
      "
    }
    println!("{s}");
}

after:

fn write_win_status(x: bool) {
    let s = if x {
      dedent!("
        Congratulations!
        You won!
      ")
    } else {
      dedent!("
        Uh oh,
        try again!
      ")
    }
    println!("{s}");
}

let s = 
assert_eq!(s, "foo\nbar");

About

Proc macro for dedenting string literals

License:MIT License


Languages

Language:Rust 100.0%