std_macro_extensions/cout/
macro.rs

1/// Print formatted output to standard output using `print!`.
2///
3/// # Parameters
4/// - `args`: A format string followed by optional expressions, just like in `print!`.
5///
6/// # Returns
7/// - Nothing. This macro prints directly to standard output.
8#[macro_export]
9macro_rules! cout {
10    ($($args: tt)*) => {
11        use std::io::{self, Write};
12        print!($($args)*);
13        let _ = io::stdout().flush();
14    };
15}
16
17/// Print a newline character and flush the standard output buffer.
18///
19/// # Parameters
20/// - (none): This macro takes no arguments.
21///
22/// # Returns
23/// - Nothing. This macro prints `\n` and flushes the output.
24#[macro_export]
25macro_rules! endl {
26    () => {{
27        cout!("\n");
28    }};
29}
30
31/// Print formatted output with a newline and flush the standard output buffer.
32///
33/// # Parameters
34/// - `args`: A format string followed by optional expressions, just like in `println!`.
35///
36/// # Returns
37/// - Nothing. This macro prints to standard output and flushes the buffer.
38#[macro_export]
39macro_rules! cout_endl {
40    ($($args:tt)*) => {
41        cout!($($args)*);
42        endl!();
43    };
44}