misc(macros.rs): {e}print{ln} use format_args!()

Allows to capture identifiers in format strings.

Signed-off-by: Anhad Singh <andypython@protonmail.com>
This commit is contained in:
Anhad Singh
2026-01-07 13:16:07 +11:00
parent 6e23a1342f
commit a97216aa93
+18 -12
View File
@@ -1,35 +1,41 @@
/// Print to stdout
#[macro_export]
macro_rules! print {
($($arg:tt)*) => ({
($($arg:tt)*) => {{
use core::fmt::Write;
let _ = write!($crate::platform::FileWriter::new(1), $($arg)*);
});
let _ = $crate::platform::FileWriter::new(1).write_fmt(format_args!($($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)*));
() => {
$crate::print!("\n")
};
($($arg:tt)*) => {
$crate::print!("{}\n", format_args!($($arg)*))
};
}
/// Print to stderr
#[macro_export]
macro_rules! eprint {
($($arg:tt)*) => ({
($($arg:tt)*) => {{
use core::fmt::Write;
let _ = write!($crate::platform::FileWriter::new(2), $($arg)*);
});
let _ = $crate::platform::FileWriter::new(2).write_fmt(format_args!($($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)*));
() => {
$crate::eprint!("\n")
};
($($arg:tt)*) => {
$crate::eprint!("{}\n", format_args!($($arg)*))
};
}
/// Lifted from libstd