origin_studio/
macros.rs

1/// Prints to the standard output.
2#[macro_export]
3macro_rules! print {
4    ($($args:tt)*) => {
5        core::fmt::write(&mut $crate::io::stdout(), format_args!($($args)*)).unwrap();
6    };
7}
8
9/// Prints to the standard output, with a newline.
10#[macro_export]
11macro_rules! println {
12    () => {
13        <$crate::io::Stdout as core::fmt::Write>::write_str(&mut $crate::io::stdout(), "\n").unwrap();
14    };
15    ($format:expr) => {
16        <$crate::io::Stdout as core::fmt::Write>::write_str(&mut $crate::io::stdout(), concat!($format, "\n")).unwrap();
17    };
18    ($format:expr, $($args:tt)*) => {
19        core::fmt::write(&mut $crate::io::stdout().lock(), format_args!(concat!($format, "\n"), $($args)*)).unwrap();
20    };
21}
22
23/// Prints to the standard error.
24#[macro_export]
25macro_rules! eprint {
26    ($($args:tt)*) => {
27        core::fmt::write(&mut $crate::io::stderr(), format_args!($($args)*)).unwrap();
28    };
29}
30
31/// Prints to the standard error< with a newline.
32#[macro_export]
33macro_rules! eprintln {
34    () => {
35        <$crate::io::Stderr as core::fmt::Write>::write_str(&mut $crate::io::stderr(), "\n").unwrap();
36    };
37    ($format:expr) => {
38        <$crate::io::Stderr as core::fmt::Write>::write_str(&mut $crate::io::stderr(), concat!($format, "\n")).unwrap();
39    };
40    ($format:expr, $($args:tt)*) => {
41        core::fmt::write(&mut $crate::io::stderr().lock(), format_args!(concat!($format, "\n"), $($args)*)).unwrap();
42    };
43}
44
45/// Writes formatted data into a buffer.
46#[macro_export]
47macro_rules! write {
48    ($dst:expr, $($arg:tt)*) => {
49        $dst.write_fmt($crate::format_args!($($arg)*))
50    };
51}
52
53/// Writes formatted data into a buffer, with a newline appended.
54#[macro_export]
55macro_rules! writeln {
56    ($dst:expr $(,)?) => {
57        $crate::write!($dst, "\n")
58    };
59    ($dst:expr, $($arg:tt)*) => {
60        $dst.write_fmt(format_args!(concat!($format, "\n"), $($args)*))
61    };
62}