Macro custom_print::define_printlike
source · macro_rules! define_printlike { ( $( #[$meta:meta] )* $name:ident, $macro:path, expect, $( $args:tt )* ) => { ... }; ( $( #[$meta:meta] )* $name:ident, $macro:path, try, $( $args:tt )* ) => { ... }; }
Expand description
Defines a print
-like macro with a given name that uses
specified write macro, error-handling policy and writer.
The writer itself is specified by the rest arguments with the define_writer
macros.
Examples
let mut string = String::new();
custom_print::define_printlike!(cprintln, writeln, expect, fmt, |value: &str| string += value);
custom_print::define_printlike!(try_println, writeln, try, fmt, |value: &str| string += value);
assert_eq!(cprintln!("first"), ());
assert_eq!(string, "first\n");
assert_eq!(try_println!("second"), Ok(()));
assert_eq!(string, "first\nsecond\n");