Skip to content

Instantly share code, notes, and snippets.

@tos-kamiya
Last active March 15, 2020 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tos-kamiya/b747d43d0c824b10096490fdb6c2bb04 to your computer and use it in GitHub Desktop.
Save tos-kamiya/b747d43d0c824b10096490fdb6c2bb04 to your computer and use it in GitHub Desktop.
Heavily restricted format macro for const str
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