From 1f800bc121eb5caa712a94dc018ec9c19c718060 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 25 Oct 2018 23:09:48 +0200 Subject: Add `dkeprintln` macro This macro functions exactly like `eprintln` while prepending the string "dome-key: error: " to all messages. Allows us to give a uniform prefix to printed rerrors. Used the `println` macro as a reference: https://doc.rust-lang.org/src/std/macros.rs.html#157-162 --- src/lib.rs | 1 + src/prefix_println.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/prefix_println.rs (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 92399dc..6a08e4b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,6 +37,7 @@ mod config; mod errors; mod key_code; mod parser; +mod prefix_println; mod trial; use parser::{Action, HeadphoneButton, MapAction, MapGroup, MapKind}; diff --git a/src/prefix_println.rs b/src/prefix_println.rs new file mode 100644 index 0000000..d1a8949 --- /dev/null +++ b/src/prefix_println.rs @@ -0,0 +1,21 @@ +#[macro_export] +macro_rules! dkeprintln { + () => (eprint!("\n")); + ($($arg:tt)*) => { + eprintln!( + "dome-key: error: {}", + format!($($arg)*), + ); + } +} + +#[cfg(test)] +mod tests { + #[test] + #[ignore] + fn dkprintln_macro() { + dkeprintln!(); + dkeprintln!("test"); + dkeprintln!("multiple arguments {}, {}", 5, 50 / 2); + } +} -- cgit v1.2.3