1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
/// Macro for printing to the standard error. /// /// Equivalent to the `errln!` macro except that a newline is not printed at /// the end of the message. /// /// Note that stderr is frequently line-buffered by default so it may be /// necessary to use `io::stderr().flush()` to ensure the output is emitted /// immediately. /// /// # Panics /// /// Panics if writing to `io::stderr()` fails. /// /// # Examples /// /// ``` /// #[macro_use] /// extern crate errln; /// /// # fn main() { /// /// use std::io::{self, Write}; /// /// err!("this "); /// err!("will "); /// err!("be "); /// err!("on "); /// err!("the "); /// err!("same "); /// err!("line "); /// /// io::stderr().flush().unwrap(); /// /// err!("this string has a newline, why not choose errln! instead?\n"); /// /// io::stderr().flush().unwrap(); /// # } /// ``` #[macro_export] macro_rules! err { ($($arg:tt)*) => {{ use std::io::Write; write!(&mut ::std::io::stderr(), $($arg)*).unwrap() }}; } /// Macro for printing to the standard err, with a newline. On all /// platforms, the newline is the LINE FEED character (`\n`/`U+000A`) alone /// (no additional CARRIAGE RETURN (`\r`/`U+000D`). /// /// Use the `format!` syntax to write data to the standard output. /// See `std::fmt` for more information. /// /// # Panics /// /// Panics if writing to `io::stderr()` fails. /// /// # Examples /// /// ``` /// #[macro_use] /// extern crate errln; /// /// # fn main() { /// /// errln!("hello there!"); /// errln!("format {} arguments", "some"); /// # } /// ``` #[macro_export] macro_rules! errln { ($fmt:expr) => (err!(concat!($fmt, "\n"))); ($fmt:expr, $($arg:tt)*) => (err!(concat!($fmt, "\n"), $($arg)*)); }