corevm-guest 0.1.16

API/SDK for CoreVM guest programs
Documentation
use crate::{yield_console_data, ConsoleStream};

/// Get standard output stream.
pub const fn stdout() -> ConsoleStream {
	ConsoleStream::Stdout
}

/// Get standard error stream.
pub const fn stderr() -> ConsoleStream {
	ConsoleStream::Stderr
}

impl core::fmt::Write for ConsoleStream {
	fn write_str(&mut self, text: &str) -> core::fmt::Result {
		yield_console_data(*self, text);
		Ok(())
	}
}

/// Print a message to the standard output stream.
#[macro_export]
macro_rules! print {
    ($($arg: tt)*) => {{
        use ::core::fmt::Write;
        let _ = ::core::write!($crate::stdout(), $($arg)*);
    }};
}

/// Print a message to the standard output stream, with a newline.
#[macro_export]
macro_rules! println {
    ($($arg: tt)*) => {{
        use ::core::fmt::Write;
        let _ = ::core::writeln!($crate::stdout(), $($arg)*);
    }};
}

/// Print a message to the standard error stream.
#[macro_export]
macro_rules! eprint {
    ($($arg: tt)*) => {{
        use ::core::fmt::Write;
        let _ = ::core::write!($crate::stderr(), $($arg)*);
    }};
}

/// Print a message to the standard error stream, with a newline.
#[macro_export]
macro_rules! eprintln {
    ($($arg: tt)*) => {{
        use ::core::fmt::Write;
        let _ = ::core::writeln!($crate::stderr(), $($arg)*);
    }};
}