corevm_guest/
formatted_output.rs

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