custom_print/macros/write.rs
1/// Calls another write macro with the specified writer, arguments and error-handling policy.
2///
3/// It propagates errors if the `try` policy is used.
4///
5/// # Panics
6///
7/// The macro panics if writing fails and the `expect` policy is used.
8///
9/// # Examples
10///
11/// ```rust
12/// use core::fmt::Write;
13/// let mut string = String::new();
14///
15/// assert_eq!(custom_print::write!(writeln, &mut string, expect, "first"), ());
16/// assert_eq!(string, "first\n");
17/// assert_eq!(custom_print::write!(writeln, &mut string, try, "second"), Ok(()));
18/// assert_eq!(string, "first\nsecond\n");
19/// ```
20#[macro_export]
21macro_rules! write {
22 ( $macro:path, $writer:expr, expect $(, $($args:tt)*)? ) => {
23 { $macro!($writer $(, $($args)*)?) }.expect("failed writing")
24 };
25 ( $macro:path, $writer:expr, try $(, $($args:tt)*)? ) => {
26 { $macro!($writer $(, $($args)*)?) }
27 };
28}