aboutsummaryrefslogtreecommitdiffstats
path: root/src/prefix_println.rs
diff options
context:
space:
mode:
authorTeddy Wing2018-10-25 23:09:48 +0200
committerTeddy Wing2018-10-25 23:12:38 +0200
commit1f800bc121eb5caa712a94dc018ec9c19c718060 (patch)
treea3af1c2feab2d4f7c77b7d61295908775864bd36 /src/prefix_println.rs
parentb6a8ce2063140e7224f9f9c94e2591259c9f85c3 (diff)
downloaddome-key-map-1f800bc121eb5caa712a94dc018ec9c19c718060.tar.bz2
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
Diffstat (limited to 'src/prefix_println.rs')
-rw-r--r--src/prefix_println.rs21
1 files changed, 21 insertions, 0 deletions
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);
+ }
+}