Last active
March 15, 2020 23:42
-
-
Save tos-kamiya/b747d43d0c824b10096490fdb6c2bb04 to your computer and use it in GitHub Desktop.
Heavily restricted format macro for const str
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! format_a0 { | |
{ a0 = $s:expr ; $x:expr } | |
=> | |
{ $x }; | |
{ a0 = $s:expr ; $x:expr , a0 } | |
=> | |
{ concat!( $x, $s ) }; | |
{ a0 = $s:expr ; $x:expr , $(a0 , $y:expr),* } | |
=> | |
{ concat!( $x, $($s , $y),* ) }; | |
} | |
const USAGE: &str = format_a0!(a0 = "foo"; | |
"Tool `", a0, "`, a super-duper fantastic one. | |
Usage: | |
", a0, " -h | |
", a0, " <file> | |
"); | |
fn main() { | |
println!("{}", USAGE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment