macro_rules! define_writer {
    ( concat, $($args:tt)* ) => { ... };
    ( fmt, $($args:tt)* ) => { ... };
    ( io, $($args:tt)* ) => { ... };
    ( $expr:expr ) => { ... };
}
Expand description

Defines a writer from writer expression arguments or from the provided one.

If more than one argument is used, the first argument specifies the writer type, and the others are used to define the expression:

If only one argument is used, the macro just returns it as a result.

Use define_try_writer if you need to define a fallible writer. This macro is used by define_printlike, define_dbglike and define_flush macros.

Examples

use core::fmt::Write;

let mut expr_string = String::new();
let mut expr_writer = custom_print::define_writer!(&mut expr_string);
let mut concat_string = String::new();
let mut concat_writer = custom_print::define_writer!(concat, |value: &str| {
    concat_string += value;
});

assert_eq!(writeln!(expr_writer, "first"), Ok(()));
assert_eq!(expr_string, "first\n");
assert_eq!(writeln!(concat_writer, "second"), Ok(()));
assert_eq!(concat_string, "second\n");