corevm_guest/
formatted_output.rs

1use crate::{yield_console_data, ConsoleStream};
2
3/// Get standard output stream.
4pub const fn stdout() -> ConsoleStream {
5	ConsoleStream::Stdout
6}
7
8/// Get standard error stream.
9pub const fn stderr() -> ConsoleStream {
10	ConsoleStream::Stderr
11}
12
13impl core::fmt::Write for ConsoleStream {
14	fn write_str(&mut self, text: &str) -> core::fmt::Result {
15		yield_console_data(*self, text);
16		Ok(())
17	}
18}
19
20/// Print a message to the standard output stream.
21#[macro_export]
22macro_rules! print {
23    ($($arg: tt)*) => {{
24        use ::core::fmt::Write;
25        let _ = ::core::write!($crate::stdout(), $($arg)*);
26    }};
27}
28
29/// Print a message to the standard output stream, with a newline.
30#[macro_export]
31macro_rules! println {
32    ($($arg: tt)*) => {{
33        use ::core::fmt::Write;
34        let _ = ::core::writeln!($crate::stdout(), $($arg)*);
35    }};
36}
37
38/// Print a message to the standard error stream.
39#[macro_export]
40macro_rules! eprint {
41    ($($arg: tt)*) => {{
42        use ::core::fmt::Write;
43        let _ = ::core::write!($crate::stderr(), $($arg)*);
44    }};
45}
46
47/// Print a message to the standard error stream, with a newline.
48#[macro_export]
49macro_rules! eprintln {
50    ($($arg: tt)*) => {{
51        use ::core::fmt::Write;
52        let _ = ::core::writeln!($crate::stderr(), $($arg)*);
53    }};
54}