Skip to content

Instantly share code, notes, and snippets.

@jwilm
Last active June 29, 2016 20:05
Show Gist options
  • Select an option

  • Save jwilm/16ce667076b854fbae55568f340c6a84 to your computer and use it in GitHub Desktop.

Select an option

Save jwilm/16ce667076b854fbae55568f340c6a84 to your computer and use it in GitHub Desktop.

Revisions

  1. jwilm revised this gist Jun 29, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion improved_println.rs
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    /// Improved println! macro that allows specifying the stdout or stderr
    /// Improved println! macro that allows specifying stdout or stderr
    ///
    /// # Examples
    ///
  2. jwilm revised this gist Jun 29, 2016. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions improved_println.rs
    Original file line number Diff line number Diff line change
    @@ -12,21 +12,21 @@
    /// zprintln!(stderr, "Hello, stderr!");
    /// ```
    macro_rules! zprintln {
    ($($arg:tt)*) => {
    println!($($arg)*);
    }
    (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);
    }
    }
  3. jwilm revised this gist Jun 29, 2016. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions improved_println.rs
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,16 @@
    /// Improved println! macro that allows specifying the 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 {
    ($($arg:tt)*) => {
    println!($($arg)*);
  4. jwilm created this gist Jun 29, 2016.
    19 changes: 19 additions & 0 deletions improved_println.rs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    macro_rules! zprintln {
    ($($arg:tt)*) => {
    println!($($arg)*);
    }
    (stdout, $($arg:tt)*) => {
    println!($($arg)*);
    };
    (stderr, $($arg:tt)*) => {{
    use std::io::Write;
    writeln!(::std::io::stderr(), $($arg)*).unwrap();
    }};
    }

    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);
    }