From 23098b694e33d53801eee5248238bd816ba45b70 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jeremy@system76.com>
Date: Mon, 17 Sep 2018 15:02:00 -0600
Subject: [PATCH] Add print, eprint, eprintln, and fix println macros

---
 src/macros.rs | 44 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 34 insertions(+), 10 deletions(-)

diff --git a/src/macros.rs b/src/macros.rs
index 18c7b6339..b98d2ce23 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -1,3 +1,37 @@
+/// Print to stdout
+#[macro_export]
+macro_rules! print {
+    ($($arg:tt)*) => ({
+        use core::fmt::Write;
+        let _ = write!($crate::platform::FileWriter(1), $($arg)*);
+    });
+}
+
+/// Print with new line to stdout
+#[macro_export]
+macro_rules! println {
+    () => (print!("\n"));
+    ($fmt:expr) => (print!(concat!($fmt, "\n")));
+    ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
+}
+
+/// Print to stderr
+#[macro_export]
+macro_rules! eprint {
+    ($($arg:tt)*) => ({
+        use core::fmt::Write;
+        let _ = write!($crate::platform::FileWriter(2), $($arg)*);
+    });
+}
+
+/// Print with new line to stderr
+#[macro_export]
+macro_rules! eprintln {
+    () => (eprint!("\n"));
+    ($fmt:expr) => (eprint!(concat!($fmt, "\n")));
+    ($fmt:expr, $($arg:tt)*) => (eprint!(concat!($fmt, "\n"), $($arg)*));
+}
+
 #[macro_export]
 macro_rules! strto_impl {
     (
@@ -101,13 +135,3 @@ macro_rules! strto_impl {
         num
     }};
 }
-
-#[macro_export]
-macro_rules! println {
-    ($($args:tt),*) => {
-        {
-            use core::fmt::Write as _Trait;
-            writeln!(::platform::FileWriter(1) $(, $args)*).expect("writing a debug message failed");
-        }
-    }
-}
-- 
GitLab