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
/// Calls another write macro with the specified writer, arguments and error-handling policy. /// /// It propagates errors if the `try` policy is used. /// /// # Panics /// /// The macro panics if writing fails and the `expect` policy is used. /// /// # Examples /// /// ```rust /// use core::fmt::Write; /// let mut string = String::new(); /// /// assert_eq!(custom_print::write!(writeln, &mut string, expect, "first"), ()); /// assert_eq!(string, "first\n"); /// assert_eq!(custom_print::write!(writeln, &mut string, try, "second"), Ok(())); /// assert_eq!(string, "first\nsecond\n"); /// ``` #[macro_export] macro_rules! write { ( $macro:path, $writer:expr, expect $(, $($args:tt)*)? ) => { { $macro!($writer $(, $($args)*)?) }.expect("failed writing") }; ( $macro:path, $writer:expr, try $(, $($args:tt)*)? ) => { { $macro!($writer $(, $($args)*)?) } }; }