Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Improved println! macro that allows specifying stdout or stderr
- ///
- /// # Examples
- ///
- /// Printing to stdout works like normal
- /// ```rust
- /// zprintln!("Hello, zprintln!");
- /// ```
- ///
- /// Printing to stderr works by passing a special argument
- /// ```rust
- /// zprintln!(stderr, "Hello, stderr!");
- /// ```
- macro_rules! zprintln {
- (stdout, $($arg:tt)*) => {
- println!($($arg)*);
- };
- (stderr, $($arg:tt)*) => {{
- use std::io::Write;
- writeln!(::std::io::stderr(), $($arg)*).unwrap();
- }};
- ($($arg:tt)*) => {
- println!($($arg)*);
- };
- }
- fn main() {
- zprintln!("normal shows up on stdout");
- zprintln!("normal shows up on stdout with arg: {}", 1);
- zprintln!(stdout, "with stdout goes to stdout: {}", 1);
- zprintln!(stderr, "with stderr goes to stderr: {}", 2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement