Skip to content

jharrilim/dedent-macro-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages